Я пытаюсь использовать функции MatchBalance()
и baltest.collect()
для создания таблиц сальдо до и после сопоставления, но постоянно получаю следующую ошибку:
Treatment indicator must be a logical variable---i.e., TRUE (1) or FALSE (0)
Я не уверен, что делаю неправильно.
Буду признателен за любую помощь в решении этой проблемы.
nsw_psid_withtreated
- это данные, с которыми я работаю
(vars = colnames (nsw_psid_withtreated) [c (2: 8,10: 11)])
> nsw.formula
re78 ~ nsw + age + educ + black + hisp + married + re74 + re75 + u74 + u75
> vars
[1] "age" "educ" "black" "hisp" "married" "re74"
[7] "re75" "u74" "u75"
> library(Matching)
> source("baltestcollect.r")
> match.nsw = Match(Y=nsw_psid_withtreated$re78, Tr=nsw_psid_withtreated$nsw, X=nsw_psid_withtreated[, vars], Weight = 1, estimand = "ATT")
> bal.nsw = formula(re78 ~ age + educ + black + hisp + married + re74 + re75 + u74 + u75)
> mb.nsw.unmatched = MatchBalance(bal.nsw, data = nsw_psid_withtreated, match.out = match.nsw)
Error in MatchBalance(bal.nsw, data = nsw_psid_withtreated, match.out = match.nsw) :
Treatment indicator must be a logical variable---i.e., TRUE (1) or FALSE (0)
Вот данные, с которыми я работаю:
> head(nsw_psid_withtreated)
# A tibble: 6 x 12
nsw age educ black hisp married re74 re75
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 0 47 12 0 0 0 0 0
2 0 50 12 1 0 1 0 0
3 0 44 12 0 0 0 0 0
4 0 28 12 1 0 1 0 0
5 0 54 12 0 0 1 0 0
6 0 55 12 0 1 1 0 0
# … with 4 more variables: re78 <dbl>, u74 <dbl>,
# u75 <dbl>, u78 <dbl>
Это также (это происходит из того же набора данных)
> str(nsw_psid_withtreated)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 2675 obs. of 12 variables:
$ nsw : num 0 0 0 0 0 0 0 0 0 0 ...
..- attr(*, "label")= chr "=1 for NSW participants, =0 otherwise"
..- attr(*, "format.stata")= chr "%9.0g"
$ age : num 47 50 44 28 54 55 47 25 44 50 ...
..- attr(*, "label")= chr "age in years"
..- attr(*, "format.stata")= chr "%9.0g"
$ educ : num 12 12 12 12 12 12 12 12 12 12 ...
..- attr(*, "label")= chr "years of education"
..- attr(*, "format.stata")= chr "%9.0g"
$ black : num 0 1 0 1 0 0 0 1 0 1 ...
..- attr(*, "label")= chr "=1 if African-American, =0 otherwise"
..- attr(*, "format.stata")= chr "%9.0g"
$ hisp : num 0 0 0 0 0 1 0 0 0 0 ...
..- attr(*, "label")= chr "=1 if Hispanic, =0 otherwise"
..- attr(*, "format.stata")= chr "%9.0g"
$ married: num 0 1 0 1 1 1 1 0 1 1 ...
..- attr(*, "label")= chr "=1 if married, =0 otherwise"
..- attr(*, "format.stata")= chr "%9.0g"
$ re74 : num 0 0 0 0 0 0 0 0 0 0 ...
..- attr(*, "label")= chr "real (inflation adjusted) earnings for 1974"
..- attr(*, "format.stata")= chr "%9.0g"
$ re75 : num 0 0 0 0 0 0 0 0 0 0 ...
..- attr(*, "label")= chr "real (inflation adjusted) earnings for 1975"
..- attr(*, "format.stata")= chr "%9.0g"
$ re78 : num 0 0 0 0 0 0 0 0 0 0 ...
..- attr(*, "label")= chr "real (inflation adjusted) earnings for 1978"
..- attr(*, "format.stata")= chr "%9.0g"
$ u74 : num 1 1 1 1 1 1 1 1 1 1 ...
..- attr(*, "label")= chr "=1 if unemployed in 1974, =0 otherwise"
..- attr(*, "format.stata")= chr "%9.0g"
$ u75 : num 1 1 1 1 1 1 1 1 1 1 ...
..- attr(*, "label")= chr "=1 if unemployed in 1975, =0 otherwise"
..- attr(*, "format.stata")= chr "%9.0g"
$ u78 : num 1 1 1 1 1 1 1 1 1 1 ...
..- attr(*, "label")= chr "=1 if unemployed in 1978, =0 otherwise"
..- attr(*, "format.stata")= chr "%9.0g"
Пожалуйста, дайте мне знать, как я могу сделать вопрос проще для понимания!