Reputation: 27
Panel data analysis newcomer here. The basic idea behind the regression that I'm hoping to run is that I want to find the effect of monthly average temperature on mortality by race over time. A portion of the panel data I have collected from publicly available sources looks something like this:
The data includes each year and month from 1999-2018. I also included mortality statistics (Tdeaths) for the following groups: American Indian, white, black, and asian.
This is the code that I inputted for the regression:
fixed1 <- felm(Tdeaths ~ TEMP + Race | Year + Month, data = Race2)
I didn't create dummy variables for each race, which I'm guessing might be part of the problem alongside the incorrect code above?
Upvotes: 0
Views: 3577
Reputation: 123
This works for me.
library(lfe)
dat <- data.frame(
"race" = sample(c("white", "black", "asian"), 72, replace=TRUE),
"year" = rep(seq(2011,2016,1), each=12),
"month" = rep(c("Jan", "Feb", "Mar", "Apr",
"May", "June", "July", "Aug",
"Sept", "Oct", "Nov", "Dec"),6),
"Tdeaths" = sample(8000:1200, 72, replace=TRUE),
"temp" = sample(45:95, 72, replace=TRUE))
str(dat)
'data.frame': 72 obs. of 5 variables:
$ race : Factor w/ 3 levels "asian","black",..: 2 2 1 2 1 3 3 1 1 3 ...
$ year : num 2011 2011 2011 2011 2011 ...
$ month : Factor w/ 12 levels "Apr","Aug","Dec",..: 5 4 8 1 9 7 6 2 12 11 ...
$ Tdeaths: int 2963 2361 5609 3795 3192 7662 1849 2808 2600 5847 ...
$ temp : int 59 70 68 80 80 61 60 55 94 55 ..
summary(est <- felm(Tdeaths ~ Temp + race | year + month, data = dat))
Call:
felm(formula = Tdeaths ~ Temp + race | year + month, data = dat)
Residuals:
Min 1Q Median 3Q Max
-3637.7 -1546.5 64.9 1309.2 3363.9
Coefficients:
Estimate Std. Error t value Pr(>|t|)
Temp 16.97 19.26 0.881 0.382
raceblack 455.74 817.24 0.558 0.579
racewhite 291.64 635.87 0.459 0.648
Residual standard error: 2156 on 52 degrees of freedom
Multiple R-squared(full model): 0.2309 Adjusted R-squared: -0.05017
Multiple R-squared(proj model): 0.02333 Adjusted R-squared: -0.3335
F-statistic(full model):0.8215 on 19 and 52 DF, p-value: 0.6728
F-statistic(proj model): 0.414 on 3 and 52 DF, p-value: 0.7436
If you are getting errors, I would go back and check all your data to make sure it is properly formatted and consistent.
If you need to obtain the estimated fixed effects use, getfe
With your data using lm
should work just fine.
lm(Tdeaths ~ Temp + race + factor(year) + factor(month), data = dat)
Upvotes: 1