简体   繁体   English

运行固定效应 plm R - 城市、年份、季度数据

[英]running fixed effects plm R - city, year, quarterly data

I am trying to estimate a model using fixed effects in R using plm package.我正在尝试使用 plm 包在 R 中使用固定效应来估计模型。 My data looks like the following below it is firm, city, year, quarter level.我的数据如下所示,它是公司、城市、年份、季度级别。 And each of these I observe sales, and income by firm and city level by year-quarter.我每季度观察公司和城市级别的销售额和收入。 My regression is income ~ sales.我的回归是收入~销售额。 That is sales on income, but looking to control for firm, and city specific unobservables.这是收入销售额,但希望控制公司和城市特定的不可观察变量。 I have 1000+ firms in my actual dataset.我的实际数据集中有 1000 多家公司。

fid = c(1,1,1,1,
    2,2,2,2,
    3,3,3,3,3,3,3,3,
    4,4,4,4,5,5,5,5,
    5,5,5,5)

cityid = c(101,101,101,101,
       102,102,102,102,102,102,102,102,103,103,103,103,
       103,103,103,103,
       104,104,104,104,
       104,104,104,104)

year = c(2000, 2000, 2000, 2000,2000,2000, 2000,2000,2001,2001,2001,2001,2002,2002,2002,2002,
     2001,2001,2001,2001,2001,2001,2001,2001,2002,2002,2002,2002)

qtr = c(1,2,3,4,1,2,3,4,1,2,3,
    4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4)

df = data.frame(fid, cityid,year,qtr,sales = sample(1:4,7, replace=T),income=30:57)

I see the plm function takes in panel specified by individual-time.我看到 plm 函数接收由个人时间指定的面板。 That is each individual is observed over various time intervals.也就是说,每个人都在不同的时间间隔内被观察到。 Now how could I use the plm package to run: 1.) firm fixed effects 2.) firm and city fixed effects 3.) firm, city, quarter fixed effects.现在我如何使用 plm 包来运行:1.) 公司固定效应 2.) 公司和城市固定效应 3.) 公司、城市、季度固定效应。

Could you distinguish?你能区分吗? I am little confused regarding the time component, and wondering if I can use firm and city fixed effects too?我对时间成分有点困惑,想知道我是否也可以使用公司和城市固定效应? In running the firm and city fixed effects, my panel would have each firm city repeated 4 times for the quarter, while each city may have multiple firms.在运行公司和城市固定效应时,我的小组将每个公司城市在本季度重复 4 次,而每个城市可能有多个公司。

For 3.) can I combine firm, city using the plm command but explicitly control for quarter in the formula (like factor(quarter))?对于 3.) 我是否可以使用 plm 命令将公司、城市结合起来,但在公式中明确控制季度(如因子(季度))?

Just wanted to get a clearer understanding of extending plm to estimate fixed effects, beyond just using time dimensions.只是想更清楚地了解扩展 plm 以估计固定效应,而不仅仅是使用时间维度。 I have already looked the vignette, but it is not totally clear.我已经看过小插图,但并不完全清楚。 So any information would be great.所以任何信息都会很棒。

I think you are a bit confused here.我想你在这里有点困惑。 The unit of analysis in your dataset is the yearly quarter (lets call it q_year, coded for example as 2000_1, 2000_2, etc.).数据集中的分析单位是年度季度(我们称之为 q_year,例如编码为 2000_1、2000_2 等)。 So you would want to generate such a variable and use it to index the time dimension.所以你会想要生成这样一个变量并用它来索引时间维度。

This you then could specify as follows:然后您可以指定如下:

model <- plm(income ~ sales + as.factor(q_year), data= df, index=c("fid", "q_year"), 
      model="within")
summary(model)

This model gives you time-fixed effects (yearly quarter) as well as firm-fixed effects.该模型为您提供时间固定效应(年季度)以及公司固定效应。 Note, that in your example data 'city' does not vary over time.请注意,在您的示例中,数据“城市”不会随时间变化。 So it would be consumed by the firm-fixed effect (the city location is a fixed firm characteristic!).因此它将被企业固定效应消耗(城市位置是固定企业特征!)。

(note: do you have data for some firms ranging over multiple years? Your example data does not have this. You would want to condens your example data to a four wave design and just take the quaters as time dimension, because this data structure effectively hold year constant for every firm.) (注意:您是否有一些公司的多年数据?您的示例数据没有这个。您可能希望将示例数据压缩为四波设计,并将四分之一作为时间维度,因为这种数据结构有效保持每家公司的年份不变。)

I would suggest using felm as an alternative to plm .我建议使用felm作为plm的替代品。 You specify all variables you want as fixed effects after a |您可以在|之后将所有想要的变量指定为固定效应| in the formula.在公式。

model <- felm(income ~ sales | cityid + fid + qtr)

You should note that city fixed effects are not needed when firms are in a unique city only.您应该注意到,当公司仅位于一个独特的城市时,不需要城市固定效应。 The reason is that a firm fixed effects already holds everything constant that's not time-varying within a firm, ie, their geographic location.原因是公司的固定效应已经使公司内所有不随时间变化的东西保持不变,即它们的地理位置。 Mathematically speaking, the fixed effects transformation subtracts the firm-level mean from the data, giving you a mean of zero.从数学上讲,固定效应转换从数据中减去公司层面的均值,得出的均值为零。 If you then form the city-level mean from all firms, so subtracting that mean from the data doesn't do anything.如果您然后从所有公司中形成城市级别的平均值,那么从数据中减去该平均值并没有任何作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM