簡體   English   中英

如何將 felm() 命令用於基本固定效果 model?

[英]How to use the felm() command for a basic fixed effects model?

面板數據分析新手在這里。 我希望運行的回歸背后的基本思想是,我想找出月平均溫度對種族死亡率隨時間變化的影響。 我從公開來源收集的部分面板數據如下所示:

在此處輸入圖像描述

數據包括 1999-2018 年的每一年和每一月。 我還包括以下群體的死亡率統計數據 (Tdeaths):美洲印第安人、白人、黑人和亞洲人。

這是我為回歸輸入的代碼:

fixed1 <- felm(Tdeaths ~ TEMP + Race | Year + Month, data = Race2)

我沒有為每場比賽創建虛擬變量,我猜這可能是問題的一部分以及上面不正確的代碼?

這對我有用。

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

如果您遇到錯誤,我會返回 go 並檢查您的所有數據以確保其格式正確且一致。
如果需要獲取估計的固定效應使用, getfe

使用您的數據lm應該可以正常工作。

lm(Tdeaths ~ Temp + race + factor(year) + factor(month), data = dat)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM