I'm working with panel data and I want to estimate a fixed effects regression with state specific trends.
In Stata, I could accomplish this by the following,
xi i.state i.year i.state*time
reg y x _I*
The above will create state dummies, year dummies, and 50 (state x time) dummies where time numerically identifies the trend (i.e. 1, 2, 3...)
In R, I can run a fixed effects model with plm or lm, for example,
plm(y ~ x, index = c("state", "year"), effect = "twoways", data = df)
lm(y ~ x + factor(state) + factor(year), data = df)
How would I include the 50 (state x time) dummies the way xi does in Stata?
I know interaction() is not what I want because that creates a new factor variable with n levels, where n = (num of states) x (num of time periods). What I'm trying to do is create 50 (state x time) variables such that state1xtime is 1,2,3... when state == 1 and zero otherwise, repeat for state2xtime, where state == 2, etc.
factor(year). I think justlm(y ~ x + factor(state) + year + factor(state):year, data = df)-- where I'm assuming you're centering your year variable. - Alex W