Dear list, I am trying to replicate some Stata results but having a tough time doing it in R. The goal is to obtain a difference-in-difference estimate in a model with simple state fixed effects. The "state" variable is a factor, but some levels are missing. It appears that Stata automatically recognizes this and works around it. It also automatically pick "ME" as the base state (see below), but trying to do the same thing in R does not yield the same results... The data is as follows: # States were assigned to treatment and control groups in 1976, and residents surveyed in 1976 and 1985 # i.year indicates the year the respondent was surveyed # i.st is a factor indicating the respondent's state of residence # i.treatment is a dummy indicating whether that individual was resident in a treatment state # hwover is the binary response variable of interest load(url("http://h1.ripway.com/rdump/d.rdata")) # load data frame "d" (slow to load, retry if 404) # Code i.st as a factor d$i.st <- factor(d$st) n.i.st <- length(levels(d$i.st)) levels(d$i.st)[14] # Level 14 == "ME" contrasts(d$i.st) <- contr.treatment(n.i.st, base = 14, contrasts=T) # Sets base level to "ME" attributes(d$i.st) # Difference-in-difference estimate reg1 <- lm(hwover ~ i.treatment*i.year + i.st, data=d, weights=weight1) summary(reg1) # Output (correctly) omit state "14" ("ME") # Estimates of average treatment effect (coefficient on i.treatment1:i.year1985) same as Stata's # So is the coefficient on i.year1985. # All other params are off. For comparison, I am pasting Stata's output below. Any ideas would be much appreciated! xi: reg hwover i.treatment*i.year i.st if st1976==1 [pw=weight1] i.treatment _Itreatment_0-1 (naturally coded; _Itreatment_0 omitted) (characteristic year[omit]: 1968 yet variable year never equals 1968; characteristic ignored) i.year _Iyear_1976-1985 (naturally coded; _Iyear_1976 omitted) i.tre~t*i.year _ItreXyea_#_# (coded as above) i.st _Ist_1-52 (_Ist_23 for st==ME omitted) (sum of wgt is 6.0268e+03) Linear regression Number of obs = 5976 F( 37, 5938) = 1.37 Prob > F = 0.0650 R-squared = 0.0083 Root MSE = .32063 ------------------------------------------------------------------------------ | Robust hwover | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- _Itreatmen~1 | .0117852 .0438655 0.27 0.788 -.0742072 .0977775 _Iyear_1985 | .0297313 .0163587 1.82 0.069 -.0023377 .0618004 _ItreXy~1985 | -.055271 .0198304 -2.79 0.005 -.0941457 -.0163963 _Ist_1 | (dropped) _Ist_2 | (dropped) _Ist_3 | -.0029799 .0325302 -0.09 0.927 -.066751 .0607912 _Ist_4 | (dropped) _Ist_5 | .0472988 .0408782 1.16 0.247 -.0328373 .1274349 _Ist_6 | .072884 .0292795 2.49 0.013 .0154855 .1302826 _Ist_7 | .0995722 .0440573 2.26 0.024 .0132039 .1859406 _Ist_8 | .0489226 .0424768 1.15 0.249 -.0343473 .1321926 _Ist_9 | (dropped) _Ist_10 | (dropped) _Ist_11 | .0591339 .0341094 1.73 0.083 -.0077329 .1260008 _Ist_12 | .0229454 .0355917 0.64 0.519 -.0468274 .0927181 _Ist_13 | (dropped) _Ist_14 | (dropped) _Ist_15 | .0058994 .0511652 0.12 0.908 -.094403 .1062018 _Ist_16 | .0830382 .0326732 2.54 0.011 .0189868 .1470896 _Ist_17 | .0579801 .0385756 1.50 0.133 -.0176421 .1336022 _Ist_18 | -.0013615 .0342379 -0.04 0.968 -.0684803 .0657573 _Ist_19 | (dropped) _Ist_20 | .0310298 .0428693 0.72 0.469 -.0530095 .1150692 _Ist_21 | (dropped) _Ist_22 | .0302868 .0448914 0.67 0.500 -.0577166 .1182902 _Ist_24 | .060111 .0334748 1.80 0.073 -.0055119 .1257338 _Ist_25 | .0003036 .0329512 0.01 0.993 -.0642926 .0648999 _Ist_26 | -.00681 .0307812 -0.22 0.825 -.0671522 .0535323 _Ist_27 | .0452638 .0503703 0.90 0.369 -.0534803 .1440078 _Ist_28 | .0869412 .0867014 1.00 0.316 -.083025 .2569075 _Ist_29 | -.0059285 .0384747 -0.15 0.878 -.0813529 .0694959 _Ist_30 | (dropped) _Ist_31 | .1421038 .0558453 2.54 0.011 .0326267 .2515808 _Ist_32 | (dropped) _Ist_33 | .0552327 .0331347 1.67 0.096 -.0097233 .1201887 _Ist_34 | (dropped) _Ist_35 | (dropped) _Ist_36 | .0245104 .0377347 0.65 0.516 -.0494633 .0984841 _Ist_37 | .0558682 .0307152 1.82 0.069 -.0043448 .1160812 _Ist_38 | (dropped) _Ist_39 | .0429489 .04253 1.01 0.313 -.0404253 .1263232 _Ist_40 | .0230925 .0301413 0.77 0.444 -.0359955 .0821804 _Ist_41 | (dropped) _Ist_42 | .0408904 .0374549 1.09 0.275 -.0325349 .1143157 _Ist_43 | (dropped) _Ist_44 | .0039713 .0431761 0.09 0.927 -.0806695 .0886122 _Ist_45 | .0425491 .0295203 1.44 0.150 -.0153213 .1004196 _Ist_46 | .0148853 .0447929 0.33 0.740 -.0729251 .1026957 _Ist_47 | .0146356 .0427135 0.34 0.732 -.0690984 .0983695 _Ist_48 | .1538798 .0817703 1.88 0.060 -.0064197 .3141793 _Ist_49 | .0191617 .0332331 0.58 0.564 -.0459873 .0843107 _Ist_50 | .033731 .0389537 0.87 0.387 -.0426325 .1100945 _Ist_51 | .0431437 .0482243 0.89 0.371 -.0513934 .1376808 _Ist_52 | (dropped) _cons | .0765964 .0365322 2.10 0.036 .00498 .1482128 ------------------------------------------------------------------------------