# NOT RUN {
library(plm)
library(lme4)
##not run
data("Crime")
#####Ceate data for REWE and BW
crime.data<-rewie.dat(Crime,c("lcrmrte","ldensity"),csvar="county",model="BW")
#random effects within estimator. Equivalent to one-way fixed effects with a random intercept
REWE<-lmer(lcrmrte_within~ldensity_within+(1|year),data=crime.data)
#Between within model w/o time intercept
BW<-lmer(lcrmrte~ldensity_within+ldensity_between+(1|county),data=crime.data)
#cross-classified between within model including time intercept
ccBW<-lmer(lcrmrte~ldensity_within+ldensity_between+(1|county)+(1|year),data=crime.data)
###Create data for REWIE and BWI
crime.data<-rewie.dat(Crime,c("lcrmrte","ldensity"),csvar="county",timevar="year",model="BWI")
#Random effects within-idiosyncratic estimator. Idiosyncratic estimator is the
#two-way fixed effects estimator.
#_common variables yield the effect of common time trends
#(period effects/homogenous within effect) on the outcome
REWIE<-lmer(lcrmrte_within~ldensity_within_idiosyncratic+
ldensity_within_common+
(1|year),data=crime.data)
#Between-within-idiosyncratic model. Idiosyncratic estimator and common estimator are
#the same as REWIE, but also includes between effects
BWI<-lmer(lcrmrte~ldensity_within_idiosyncratic+
ldensity_within_common+
ldensity_between+
(1|year)+(1|county),data=crime.data)
# }
Run the code above in your browser using DataLab