I'm trying to re-create an analysis done using Stata
function xtreg
(though I don't have the code) with R
package plm
, and I'm having trouble translating between the two. A minimal example of the model I'm trying to estimate would be as follows:
$$ \text{Dependent}_{i,t} = \beta_0 + \gamma_i + \delta_t + \beta_1*\text{Dependent}_{i,t-1} + \beta_2*\text{Independent}_{i,t} + \epsilon_{i,t} $$
where $\gamma_i$ is a control for the cross-sectional factor (States), $\delta_t$ is a control for each time period (Year), $\text{Dependent}_{i,t}$ is a dependent variable in the form of a proportion, and $\text{Independent}_{i,t}$ is an attribute of a record that changes with both the cross-sectional and time component of the data.
I've attempted to estimate the coefficients for the model using R
with the following (generalized) code:
model <- plm(Dependent_it ~ Independent_it + lag(Dependent_it,1),
data = data,
method = "within", #fixed effects model
effect = "twoway", #does the gamma_i and delta_t parts (I think)
index = c("State", "Year")
)
I've tried to re-create it in Stata
using the following (after running xtset State Year, yearly
of course)
xtreg Dependent Independent l.Dependent i.Year, fe
I get different results, so I must be doing something wrong with either xtreg
or plm
, or both. Can someone enlighten me as to if I've coded the above model appropriately in either language?