1
$\begingroup$

Year as a dummy ( 1995 is the omitted year):

Call:
plm(formula = mrateunder5 ~ GDPPPP + factor(Year), data = FinalData, 
    model = "within", index = "Country")

Unbalanced Panel: n = 47, T = 1-3, N = 69

Residuals:
    Min.  1st Qu.   Median  3rd Qu.     Max. 
-11.4818  -1.9533   0.0000   1.9816  11.4818 

Coefficients:
                    Estimate  Std. Error t-value  Pr(>|t|)    
GDPPPP             0.0134389   0.0044836  2.9974   0.00773 ** 
factor(Year)2000 -15.4565645   6.2679791 -2.4660   0.02394 *  
factor(Year)2005 -39.5441044   6.6982650 -5.9036 1.374e-05 ***
factor(Year)2010 -59.1835897   9.9644448 -5.9395 1.276e-05 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares:    6722.6
Residual Sum of Squares: 1237.5
R-Squared:      0.81592
Adj. R-Squared: 0.30457
F-statistic: 19.9453 on 4 and 18 DF, p-value: 2.0253e-06

When I include Year and Country as dummy variables, I have the same coefficient value on GDP.

Year as a Fixed Effect:

Call:
plm(formula = mrateunder5 ~ GDPPPP, data = FinalData, model = "within", 
    index = c("Year", "Country"))

Unbalanced Panel: n = 4, T = 4-28, N = 69

Residuals:
   Min. 1st Qu.  Median 3rd Qu.    Max. 
-59.296 -24.494  -6.722  19.180 107.636 

Coefficients:
         Estimate Std. Error t-value  Pr(>|t|)    
GDPPPP -0.0251533  0.0030549 -8.2338 1.249e-11 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares:    183330
Residual Sum of Squares: 89024
R-Squared:      0.5144
Adj. R-Squared: 0.48405
F-statistic: 67.7951 on 1 and 64 DF, p-value: 1.2488e-1

As you can see, the coefficient estimate on "GDPPPP" is different. The results in the second model are my preferred results (negative coefficient, as higher GDP levels lead to lower mortality rates).

Why do these differ - are they supposed to match?

I think it could be because I have incomplete data (data for some countries for some years is missing - e.g., for Afghanistan I am missing the first two time periods (1995 and 2000) but I have the Afghanistan data for 2005 and 2010).

Does one of my models is drop incomplete data? Which one? Is there a way to make the models match?

$\endgroup$
3
  • $\begingroup$ That said, it's very helpful if you can share a sample of data (e.g. using dput()) that someone can copy and paste to get the same result. $\endgroup$ Commented Nov 29, 2021 at 20:25
  • $\begingroup$ Whether or not the models "should" match, if perhaps one is a reparameterization of the other with a transformation of coefficients, etc, seem like statistical questions to me, not programmatic ones. I think you'll get better answers and faster answers at Cross Validated. $\endgroup$ Commented Nov 29, 2021 at 20:36
  • 4
    $\begingroup$ You should not prefer a model because its results accord with your preconceptions. In this case the second model is awful compared to the first: just look at the distribution of residuals. $\endgroup$
    – whuber
    Commented Nov 29, 2021 at 21:49

1 Answer 1

6
$\begingroup$

The two commands you use estimate two different models. To illustrate, I use the Grunfeld data set; you can think of its firm variable as your Country variable and its year variable as your Year variable.

Your 1st model:

You effectively estimate a two-ways fixed effects model where the time fixed effect are explicitly modelled via dummies (the part +factor(year)) (sometimes this is called LSDV - least squares dummies (approach); here you have the time dimension as explicit dummies and the individual dimension implictly).

You can have that model also via the effect argument by setting it to "twoways", leaving out the explicit dummies (this is the Frisch-Waugh-Lovell theorem [1]). The coefficient for value is in both cases 0.17997:

library(plm)
data("Grunfeld", package = "plm")

# corresponds to your 1st model:
plm(formula = inv ~ value + factor(year), data = Grunfeld, 
    model = "within", index = c("firm", "year"))
#> 
#> Model Formula: inv ~ value + factor(year)
#> 
#> Coefficients:
#>            value factor(year)1936 factor(year)1937 factor(year)1938 
#>          0.17997        -38.10560        -66.31173        -20.32730 
#> factor(year)1939 factor(year)1940 factor(year)1941 factor(year)1942 
#>        -59.30898        -36.24559         -1.50065         18.71706 
#> factor(year)1943 factor(year)1944 factor(year)1945 factor(year)1946 
#>         -6.73151         -9.46490        -26.44724         -0.73981 
#> factor(year)1947 factor(year)1948 factor(year)1949 factor(year)1950 
#>         34.82737         47.09646         28.68980         29.79853 
#> factor(year)1951 factor(year)1952 factor(year)1953 factor(year)1954 
#>         36.74272         52.86057         64.20592         69.57366

# same with effect = "twoways"
plm(formula = inv ~ value , data = Grunfeld, 
    model = "within", index = c("firm", "year"), effect = "twoways")
#> 
#> Model Formula: inv ~ value
#> 
#> Coefficients:
#>   value 
#> 0.17997

Your 2nd model:

You switched the index variables in argument index, so plm takes the time dimension as the observational unit (individual index) and vice versa, see also the output n = 4, T = 4-28, N = 69 in your 2nd model vs. n = 47, T = 1-3, N = 69 in your first.

You effectively estimate a one-way time effect model . You can have the same model without the confusioning mix up of invididual and time dimension and - again - by using the effect argument (set to "time"). You get the same coefficent for value: 0.13983.

# your approach
plm(formula = inv ~ value, data = Grunfeld, 
    model = "within", index = c("year", "firm"))
#> 
#> Model Formula: inv ~ value
#> 
#> Coefficients:
#>   value 
#> 0.13983

# one-way time effect model
plm(formula = inv ~ value, data = Grunfeld, 
    model = "within", index = c("firm", "year"), effect = "time")
#> 
#> Model Formula: inv ~ value
#> 
#> Coefficients:
#>   value 
#> 0.13983

I suggest you revisit the plm package first vignette for further instructions. The summary() command on estimated models will give you a nice headline about the model estimated if you make use of the index and the effect arguments in a proper way.

The fixed effects as in the dummy-based model can be obtained in the other models via commandfixef, here for the time effects in the two-ways model with arguments effect = "time" and type = "dfirst":

fixef(plm(formula = inv ~ value , data = Grunfeld, model = "within", 
      index = c("firm", "year"), effect = "twoways"),
   effect = "time", type = "dfirst")
#>      1936      1937      1938      1939      1940      1941      1942      1943 
#> -38.10560 -66.31173 -20.32730 -59.30898 -36.24559  -1.50065  18.71706  -6.73151 
#>      1944      1945      1946      1947      1948      1949      1950      1951 
#>  -9.46490 -26.44724  -0.73981  34.82737  47.09646  28.68980  29.79853  36.74272 
#>      1952      1953      1954 
#>  52.86057  64.20592  69.57366
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.