rewie_dat: Function to transform data for mixed modeling with REWE,...

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Centers data for the specified variables. For REWE and BW, data are centered to provide cross-section means and within variation. For REWIE and BWI, data are centered to provide cross-section means, time means for the within variation, and the idiosyncratic variation centered on both cross-section and time means.

Usage

1
rewie.dat(df,vars.to.center,csvar,timevar=NULL,model="BWI")

Arguments

df

df is the data frame containing the variables to transform.

vars.to.center

The variables to be transformed.

timevar

is a character string providing the name of the time indicator variable.

csvar

is a character string providing the name of the cross-section indicator variable.

model

specifies the type of transformation. Can be one of the following: "BWI","REWE","REWIE", or"BW". For REWE and BW, the within variation and cross-section means are returned. For REWIE and BWI, the cross-section means, idiosyncratic variation, and time means of the within variation are returned.

Details

Transforms panel data to conduct panel analysis with random effects within estimators and its extensions. The variables are centered on their time and cross-section means to be passed to lmer() for mixed modeling. The time means are the means of the differences between the cross-section means and the observations. The idiosyncratic variation is the observation twice centered (minus the cross-section mean, then minus the time mean). When passed to a mixed model, the idiosyncratic variation returns the same estimate as two-way fixed effects, the between variation gives the between estimator, and the time mean gives the period effect of the variable. Other time invariant and cross-section invariant variables can also be included, but these models do not need to be transformed.

Value

Returns a dataframe including the transformed values to be used in mixed modeling.

Author(s)

Scott Duxbury, Assistant Professor of Sociology at University of North Carolina, Chapel Hill

See Also

edgeprob

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)

rewie documentation built on July 1, 2020, 6:53 p.m.

Related to rewie_dat in rewie...