You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

plm包固定效应回归:ID索引顺序影响的技术咨询

Why does the order of ID variables (Company vs Year) in plm's index affect fixed effect regression results?

The core reason for the differences in your regression results lies in what the index parameter in plm actually controls when using a one-way within model. Let's break this down step by step:

1. How plm interprets the index parameter for one-way fixed effects

When you set model="within" without specifying effect="twoways", plm defaults to a one-way fixed effect model—it only controls for fixed effects of the first variable in your index vector:

  • For index=c("Year","Company"): The model treats Year as the "individual" dimension, so it estimates and removes year-specific fixed effects (absorbing unobserved heterogeneity that's constant across all firms in a given year).
  • For index=c("Company","Year"): The model treats Company as the "individual" dimension, so it estimates and removes firm-specific fixed effects (absorbing unobserved heterogeneity that's constant for a given firm across all years).

These are two entirely distinct models, so divergent results are expected.

2. Matching output details to this explanation

Let's cross-reference your regression outputs to confirm this logic:

Panel structure differences

  • MV_Year output shows n = 17 (number of "individuals" = 17 years) and T = 557-4280 (number of firms per year).
  • MV_Company output shows n = 5911 (number of "individuals" = 5911 firms) and T = 1-17 (number of years per firm).

This directly confirms which dimension is being used for fixed effects.

Coefficient estimates

Differences in coefficients (e.g., LEV shifts from -1.95 to -1.88, RDlog from 0.131 to 0.139) occur because each fixed effect absorbs different sources of omitted variable bias:

  • Year fixed effects account for economy-wide shocks that hit all firms in a year (e.g., macroeconomic trends, annual policy changes).
  • Firm fixed effects account for time-invariant firm traits (e.g., corporate culture, inherent business model differences).

Each adjustment reshapes the remaining variation in your dependent variable that can be explained by the covariates.

R-squared and residual statistics

  • Total Sum of Squares: For one-way within models, this is the sum of squares after de-meaning the data by the individual dimension. De-meaning by firms (which have smaller cross-sectional variation over time) results in a smaller total sum of squares (58168 vs 102610) compared to de-meaning by years.
  • Adjusted R-squared: The larger drop in adjusted R² for MV_Company (0.726 vs 0.828) stems from the far larger number of fixed effects being estimated (5911 firm effects vs 17 year effects)—this reduces degrees of freedom more drastically, leading to a lower adjusted value.
  • F-statistic degrees of freedom: The residual DF for MV_Year is 29890 - 17 (year effects) - 4 (covariates) = 29869, while for MV_Company it's 29890 - 5911 (firm effects) - 4 = 23975—exactly matching your outputs.

3. How to run a two-way fixed effect model

If you want to control for both firm and year fixed effects (the standard approach in many panel data analyses), explicitly set effect="twoways" in your plm call:

MV_Twoway <- plm(MVlog ~ LEV + Size + DY + RDlog, 
                 data=Values, 
                 model="within", 
                 index=c("Company", "Year"), 
                 effect="twoways")

This model will absorb both time-invariant firm characteristics and year-specific shocks, producing results distinct from either of your one-way models.

内容的提问来源于stack exchange,提问作者Aria T

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 08:22:36