Method-1
## http://stats.stackexchange.com/questions/88409/which-test-should-be-used-to-compare-two-mean-differences
setwd("/Users/subasishdas1/Dropbox/---- TRB_2017 ----/Difference in Differences")
aa1 <- read.csv("aa1.csv")
attach(aa1)
## aa1$Before1 <- scale(Before,scale=F)
## aa1[c(4,2,3)]
## summary(lm(After~Before1*Condition,aa1))
summary(lm(After~scale(Before,scale=F)*Condition,aa1))
##
## Call:
## lm(formula = After ~ scale(Before, scale = F) * Condition, data = aa1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -20.073 -18.659 -0.847 11.915 45.177
##
## Coefficients:
## Estimate Std. Error
## (Intercept) 117.75391 7.01854
## scale(Before, scale = F) 1.23430 0.07369
## ConditionTreatment Sites -58.16038 9.92878
## scale(Before, scale = F):ConditionTreatment Sites -0.84794 0.10516
## t value Pr(>|t|)
## (Intercept) 16.778 1.15e-10 ***
## scale(Before, scale = F) 16.750 1.17e-10 ***
## ConditionTreatment Sites -5.858 4.16e-05 ***
## scale(Before, scale = F):ConditionTreatment Sites -8.063 1.25e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 20.7 on 14 degrees of freedom
## Multiple R-squared: 0.9576, Adjusted R-squared: 0.9486
## F-statistic: 105.5 on 3 and 14 DF, p-value: 7.549e-10
Method-2
## http://www.princeton.edu/~otorres/DID101R.pdf
## Same Data; melted
aa2 <- read.csv("aa2.csv")
aa2$did = aa2$BA1 * aa2$Condition1
aa2[c(1, 4, 5, 6)]
## Count BA1 Condition1 did
## 1 20 0 0 0
## 2 57 0 0 0
## 3 8 0 0 0
## 4 57 0 0 0
## 5 161 0 0 0
## 6 319 0 0 0
## 7 14 0 0 0
## 8 45 0 0 0
## 9 81 0 0 0
## 10 21 0 1 0
## 11 118 0 1 0
## 12 39 0 1 0
## 13 118 0 1 0
## 14 126 0 1 0
## 15 358 0 1 0
## 16 65 0 1 0
## 17 116 0 1 0
## 18 115 0 1 0
## 19 32 1 0 0
## 20 42 1 0 0
## 21 6 1 0 0
## 22 42 1 0 0
## 23 172 1 0 0
## 24 398 1 0 0
## 25 12 1 0 0
## 26 75 1 0 0
## 27 87 1 0 0
## 28 9 1 1 1
## 29 47 1 1 1
## 30 27 1 1 1
## 31 47 1 1 1
## 32 114 1 1 1
## 33 148 1 1 1
## 34 51 1 1 1
## 35 75 1 1 1
## 36 79 1 1 1
didreg = lm(Count ~ BA1 + Condition1 + did, data = aa2)
summary(didreg)
##
## Call:
## lm(formula = Count ~ BA1 + Condition1 + did, data = aa2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -98.56 -55.25 -19.33 7.00 301.78
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 84.67 31.87 2.656 0.0122 *
## BA1 11.56 45.08 0.256 0.7993
## Condition1 34.89 45.08 0.774 0.4446
## did -64.78 63.75 -1.016 0.3172
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 95.62 on 32 degrees of freedom
## Multiple R-squared: 0.0438, Adjusted R-squared: -0.04584
## F-statistic: 0.4886 on 3 and 32 DF, p-value: 0.6926
didreg = lm(Count ~ BA1*Condition1, data = aa2)
summary(didreg)
##
## Call:
## lm(formula = Count ~ BA1 * Condition1, data = aa2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -98.56 -55.25 -19.33 7.00 301.78
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 84.67 31.87 2.656 0.0122 *
## BA1 11.56 45.08 0.256 0.7993
## Condition1 34.89 45.08 0.774 0.4446
## BA1:Condition1 -64.78 63.75 -1.016 0.3172
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 95.62 on 32 degrees of freedom
## Multiple R-squared: 0.0438, Adjusted R-squared: -0.04584
## F-statistic: 0.4886 on 3 and 32 DF, p-value: 0.6926