I have estimated some repeated measures Fixed Effects models, with a nested error component, based on on grouping variables, i.e. non-nested models, using plm. I am now interested to
- test if the full models are significantly different, i.e. $$H_o: \beta_{Female} = \beta_{Male}$$ where $\beta_{Female}$ is the full model for
Females
and $\beta_{Male}$ is the full model forMales
and - subsequently test selected regression coefficients between two groups, i.e. $$H_o: \beta_{Female == year1.5} = \beta_{Male == year1.5}$$ where $\beta_{Female == year1.5}$ is the regression coefficient for females at
year1.5
, and $\beta_{Male == year1.5}$ is the regression coefficient for males atyear1.5
.
I will illustrate the situation using the below working example,
First, some packages needed,
# install.packages(c("plm","texreg","tidyverse","lmtest"), dependencies = TRUE)
library(plm); library(lmtest); require(tidyverse)
Second, some data preparation,
data(egsingle, package = "mlmRev")
dta <- egsingle %>% mutate(Female = recode(female,.default = 0L,`Female` = 1L))
Third, I estimate a set of models for each gender in data
MoSpc <- as.formula(math ~ Female + size + year)
dfMo = dta %>% group_by(female) %>%
do(fitMo = plm(update(MoSpc, . ~ . -Female),
data = ., index = c("childid", "year", "schoolid"), model="within") )
Forth, lets look at the two estimated models,
texreg::screenreg(dfMo[[2]], custom.model.names = paste0('FE: ', dfMo[[1]]))
#> ===================================
#> FE: Female FE: Male
#> -----------------------------------
#> year-1.5 0.79 *** 0.88 ***
#> (0.07) (0.10)
#> year-0.5 1.80 *** 1.88 ***
#> (0.07) (0.10)
#> year0.5 2.51 *** 2.56 ***
#> (0.08) (0.10)
#> year1.5 3.04 *** 3.17 ***
#> (0.08) (0.10)
#> year2.5 3.84 *** 3.98 ***
#> (0.08) (0.10)
#> -----------------------------------
#> R^2 0.77 0.79
#> Adj. R^2 0.70 0.72
#> Num. obs. 3545 3685
#> ===================================
#> *** p < 0.001, ** p < 0.01, * p < 0.05 #>
Now, I want to test if these two (linear OLS) models are significantly different, cf. point1 above. I looked around SO and the internet and some suggest that I need to use plm::pFtest()
, also suggested here, which I have tried, but I'm not convinced. I would have imagined some test for non-nested models, possible Cox test, lmtest::coxtest
, but I am not sure at all. If someone here could possibly help me.
I tried,
plm::pFtest(dfMo[[1,2]], dfMo[[2,2]])
# >
# > F test for individual effects
# >
# >data: update(MoSpc, . ~ . - Female)
# >F = -0.30494, df1 = 113, df2 = 2693, p-value = 1
# >alternative hypothesis: significant effects
and,
lmtest::coxtest(dfMo[[1,2]], dfMo[[2,2]])
# > Cox test
# >
# > Model 1: math ~ size + year
# > Model 2: math ~ size + year
# > Estimate Std. Error z value Pr(>|z|)
# > fitted(M1) ~ M2 0.32 1.66695 0.1898 0.8494
# > fitted(M2) ~ M1 -1222.87 0.13616 -8981.1963 <2e-16 ***
# > ---
# > Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# > Warning messages:
# > 1: In lmtest::coxtest(dfMo[[1, 2]], dfMo[[2, 2]]) :
# > models fitted on different subsets
# > 2: In lmtest::coxtest(dfMo[[1, 2]], dfMo[[2, 2]]) :
# > different dependent variables specified
Second, I am interested to compare regression coefficients between two groups. Say, is the estimate for year1.5
of 3.04 significantly different from 3.17? Cf. point 2 above.
Please ask if any of the above is not clear and I will be happy to elaborate. Any help will be greatly appreciated!
I realize this question is a bit programming like, but I initially posted it in SO. However, DWin was kind enough to point out that the question belonged in CrossValidated and migrated it here.
fixed-effects-model r plm nested-data hypothesis-testing repeated-measures panel-data mixed-model regression panel-data non-nested-models nested-models
plm
package, at stackoverflow.com. I will take more care in the future to post my questions in the appropriate place. Thanks. $\endgroup$plm(math ~ Female * (x1 + x2))
. To test the first null hypothesis, you just run F test for all coefficients associated withFemale:x1
,Female:x2
. To test the second null, you just need t test the parameter associated withFemale:year1.5
. $\endgroup$suest
to see if two models are significantly different. There's asuest()
function around in a package for R but I doubt that it is the same. In Statasuest
is related to "Seemingly unrelated estimation". Note, thatsureg
is somewhat different. I am also interested in an R solution. Hope that would help somehow. $\endgroup$