Data Preparation
Import libraries:
library(stringr)
library(estimatr)
library(readxl)
library(dplyr)
##
## 次のパッケージを付け加えます: 'dplyr'
## 以下のオブジェクトは 'package:stats' からマスクされています:
##
## filter, lag
## 以下のオブジェクトは 'package:base' からマスクされています:
##
## intersect, setdiff, setequal, union
Import data
df <- read_excel(
file.path("NHIS2009_clean.xlsx"))
data<- df
Data preparation for analysis: cleaned
Only housholds with one husband and one wife. No observation should have a perweight value of zero.
NHIS2009 <- data %>%
filter(marradult & perweight != 0)
At least one is employed.
NHIS2009 <- NHIS2009 %>%
group_by(serial) %>%
filter(sum(empl) > 0)
Between ages 26-59.
NHIS2009 <- NHIS2009 %>%
filter(age >= 26 & age <= 59)
Drop single person HHS
NHIS2009 <- NHIS2009 %>%
group_by(serial) %>%
filter(n()>1)
Remove missing data
NHIS2009 <- NHIS2009 %>%
group_by(serial) %>%
mutate(numfem = sum(fml)) %>%
filter(numfem == 1) %>%
select(-numfem)
Create a data frame of just wives.
wives <- NHIS2009 %>%
filter(fml == 1) %>%
filter(fml != 0) %>%
filter(sex == "Female")
1-2 Ceterius Paribus: Replicate Wives (a)In the health outcome different between the treated and untreated?
Regress the outcome variable on the treatment variable.
lm_robust(hlth~hi,
data = wives, weights = perweight, se_type = "HC1") %>%
summary()
##
## Call:
## lm_robust(formula = hlth ~ hi, data = wives, weights = perweight,
## se_type = "HC1")
##
## Weighted, Standard error type: HC1
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|) CI Lower CI Upper DF
## (Intercept) 3.6231 0.03302 109.74 0.000e+00 3.5583 3.6878 9393
## hi 0.3943 0.03522 11.19 6.573e-29 0.3253 0.4634 9393
##
## Multiple R-squared: 0.01864 , Adjusted R-squared: 0.01853
## F-statistic: 125.3 on 1 and 9393 DF, p-value: < 2.2e-16
(b)Ceterius Paribus(Balance Check)
variables <- c("nwhite", "age", "yedu", "famsize", "empl", "inc")
for (var in variables) {
formula <- as.formula(paste(var, "~ hi"))
model <- lm_robust(formula, data = wives, se_type = "HC1")
print(summary(model))
}
##
## Call:
## lm_robust(formula = formula, data = wives, se_type = "HC1")
##
## Standard error type: HC1
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|) CI Lower CI Upper DF
## (Intercept) 0.18339 0.01018 18.012 2.454e-71 0.163433 0.20335 9393
## hi 0.01824 0.01113 1.639 1.013e-01 -0.003576 0.04006 9393
##
## Multiple R-squared: 0.0002719 , Adjusted R-squared: 0.0001655
## F-statistic: 2.686 on 1 and 9393 DF, p-value: 0.1013
##
## Call:
## lm_robust(formula = formula, data = wives, se_type = "HC1")
##
## Standard error type: HC1
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|) CI Lower CI Upper DF
## (Intercept) 39.520 0.2173 181.89 0.000e+00 39.094 39.946 9393
## hi 2.631 0.2380 11.06 3.077e-28 2.164 3.097 9393
##
## Multiple R-squared: 0.01205 , Adjusted R-squared: 0.01194
## F-statistic: 122.2 on 1 and 9393 DF, p-value: < 2.2e-16
##
## Call:
## lm_robust(formula = formula, data = wives, se_type = "HC1")
##
## Standard error type: HC1
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|) CI Lower CI Upper DF
## (Intercept) 11.359 0.09204 123.42 0.000e+00 11.179 11.540 9393
## hi 2.913 0.09655 30.18 5.284e-191 2.724 3.103 9393
##
## Multiple R-squared: 0.1269 , Adjusted R-squared: 0.1268
## F-statistic: 910.6 on 1 and 9393 DF, p-value: < 2.2e-16
## Warning in storage.mode(v) <- "double": 強制変換により NA が生成されました
## 2 coefficients not defined because the design matrix is rank deficient
##
## Call:
## lm_robust(formula = formula, data = wives, se_type = "HC1")
##
## Standard error type: HC1
##
## Coefficients: (2 not defined because the design matrix is rank deficient)
## Estimate Std. Error t value Pr(>|t|) CI Lower CI Upper DF
## (Intercept) NA NA NA NA NA NA NA
## hi NA NA NA NA NA NA NA
##
## Multiple R-squared: NA , Adjusted R-squared: NA
##
## Call:
## lm_robust(formula = formula, data = wives, se_type = "HC1")
##
## Standard error type: HC1
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|) CI Lower CI Upper DF
## (Intercept) 0.5412 0.01311 41.28 0.00e+00 0.5155 0.5669 9393
## hi 0.2164 0.01396 15.50 1.59e-53 0.1891 0.2438 9393
##
## Multiple R-squared: 0.03053 , Adjusted R-squared: 0.03043
## F-statistic: 240.3 on 1 and 9393 DF, p-value: < 2.2e-16
##
## Call:
## lm_robust(formula = formula, data = wives, se_type = "HC1")
##
## Standard error type: HC1
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|) CI Lower CI Upper DF
## (Intercept) 43641 924.7 47.20 0 41829 45454 9393
## hi 59722 1111.9 53.71 0 57543 61902 9393
##
## Multiple R-squared: 0.1442 , Adjusted R-squared: 0.1441
## F-statistic: 2885 on 1 and 9393 DF, p-value: < 2.2e-16