Cross-classified APC models

Welcome to the forum for runmlwin users. Feel free to post your question about runmlwin here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Go to runmlwin: Running MLwiN from within Stata >>
Post Reply
Posts: 7
Joined: Fri Jan 06, 2017 4:20 pm

Cross-classified APC models

Post by davidekstam »

Hi forum! I have recently picked up runMLwiN for my dissertation work. I am working on an age-period-cohort (APC) analysis of the change in tolerance toward homosexuality that has occurred in recent years. As part of this paper I intend to employ the cross-classified random effects APC model developed by Yang & Land (2006, 2008), which treats individuals as nested within time periods and birth cohorts (hence the cross-classified structure of the data). In line with this, I want to model age and other (categorical) covariates as fixed effects at level 1, while I want to include period (10 surveys) and cohort (10 10-birthyear groups) as random effects at level 2.

However, I have had some problems implementing this model. In Stata I have been trying the xtmixed command:

Code: Select all

xtmixed tolerance age || _all: R.surveyyear || _all: R.cohort
Running this, I receive one estimator for each of the level 2 variables, instead of a random effects coefficient for each individual period k and each individual cohort group j. Individual predictions for the random effects can be obtained by running:

Code: Select all

 predict X, reffects
afterwards, but it appears like Stata is unable to display the individual random effects regression coefficients that I need.

This is the reason to why I have picked up runMlwiN, but so far I have struggled in figuring out how the code should be written. The code I have been running so far is:

Code: Select all

. runmlwin tolerance cons age, level3(cons: cohort1-cohort10, diagonal) level2(cons: period1-period10, diagonal) level1(id: cons) nosort
Where cohort1-cohort10 and period1-period10 are generated from:

Code: Select all

. quietly tabulate birthyear10, generate(cohort)
. quietly tabulate survey, generate(period)
The output of this model is very strange, however, and not in line with results from various fixed effects models and graphical plots. I have scanned the web for guidance but found none for APC analysis, so I would really appreciate if anyone could give me a helping hand. As an end note I should add that I am well aware that the cross-classified random effects APC model has been severely questioned (Bell and Jones, 2014), but my use of the model will mostly be of supplementary nature.

Kind regards,

David Ekstam
PhD candidate
Department of Government
Uppsala University

Yang, Y., Land, K.C., 2008. Age–Period–Cohort Analysis of Repeated Cross-Section Surveys: Fixed or Random Effects? Sociological methods & research 36, 297–326.

Yang, Y., Land, K.C., 2006. A mixed models approach to the age-period-cohort analysis of repeated cross-section surveys, with an application to data on trends in verbal test scores. Sociological methodology 36, 75–97.

Bell, A., Jones, K., 2014. Another’futile quest’? A simulation study of Yang and Land’s Hierarchical Age-Period-Cohort model. Demographic Research 30, 333.

Posts: 17
Joined: Mon Jun 03, 2013 3:19 pm

Re: Cross-classified APC models

Post by andrewjdbell »

Hi David (I know I emailed you too, but in case others are interested...)

With your model, you should only be getting one variance for period and one for cohort. This is the variance of your cohort / period residuals (your residuals are not regression coefficients so will not be displayed as such). However, you can estimate those residuals, as you say, using

Code: Select all

predict X, reffects
, which should give you what you need (the individual year / individual cohort effects). (Note you also don't need to use the "_all: R." notation for both cross-classified variables, you only need to do so for one).

This is the same with runmlwin, you want to have a single variance estimated, and use "residuals(u)" to output residual predictions. Also, for runmlwin you would need to use MCMC and specify that you are using a cross-classified model. So something like this should work:

Code: Select all

mat b - (1,1,1,1) //to set starting values
runmlwin tolerance cons age, level3(birthyear10: cons, residuals(v)) level2(survey: cons, residuals(u)) level1(id: cons) mcmc(cc) inits(b) nopause
You may need to adjust burn in / iterations etc.

Hope that helps!

PS: To reiterate David's last point: the HAPC model doesn't solve the APC identification problem as its authors claim it does, so should be used with caution/skepticism, especially where monotonic period and cohort trends are found (see the paper he cited).

Posts: 7
Joined: Fri Jan 06, 2017 4:20 pm

Re: Cross-classified APC models

Post by davidekstam »

Edit: Thanks for the reply (both here and via email)! When I first run the model the estimates were all strange, even when I had a burnin of 5000 and a chain of 50000. However, I increased the burnin to 100000 and the chain to 500000 (I used starting values of 1,1,1,1,1), and this produced estimates that look correct (the b-estimates mirror those given by the mixed command). However, the calculations took quite some time. Is there any formula/guideline for finding appropriate starting values and/or burnin length? Also, is it possible to conduct BIC/AIC or a similar post estimation after this model?

Code: Select all

. runmlwin homosex cons age_new, level3(cohort10: cons, residuals(v)) level2(survey: cons, residuals(u)) level1(id: cons) mcmc(cc burnin(100000) cha
> in(500000))initsb(b) nopause
MLwiN 2.36 multilevel model                     Number of obs      =     10110
Normal response model
Estimation algorithm: MCMC

                |   No. of       Observations per Group
 Level Variable |   Groups    Minimum    Average    Maximum
       cohort10 |       10         22     1011.0       1829
         survey |       10        847     1011.0       1153

Burnin                     =     100000
Chain                      =     500000
Thinning                   =          1
Run time (seconds)         =        503
Deviance (dbar)            =   51836.67
Deviance (thetabar)        =   51818.06
Effective no. of pars (pd) =      18.61
Bayesian DIC               =   51855.29
     homosex |      Mean    Std. Dev.     ESS     P       [95% Cred. Interval]
        cons |   5.861196   .5060489     1551   0.000     4.877015     6.90128
     age_new |  -.0319923   .0043518    42114   0.000    -.0403621    -.023063

   Random-effects Parameters |     Mean   Std. Dev.   ESS     [95% Cred. Int]
Level 3: cohort10            |
                   var(cons) |  .1064534  .0918986 103870   .0210169  .3378753
Level 2: survey              |
                   var(cons) |  2.080531  1.313617  77449    .754991  5.419645
Level 1: id                  |
                   var(cons) |  9.869963  .1389264 499803    9.60141  10.14608

Posts: 7
Joined: Mon Oct 19, 2015 3:11 pm

Re: Cross-classified APC models

Post by francescomolteni »

dear all,
I give new life to this topic. I am doing something similar to David.
My dv is probability to attend Church weekly (range 0-1)
I have age variable, cohort (9 categories) and period (7 categories)

I estimate the model using runmlwin

Code: Select all

 global MLwiN_path "C:\Program Files (x86)\MLwiN v2.35\x64\mlnscript.exe"
mat b = (1,1,1,1,1)
runmlwin 	attendp cons ager, ///
			level3(cohort_cat: cons, residuals(v)) 	///
			level2(period_cat: cons, residuals(u)) ///
			level1(id: cons) ///
			mcmc(cc burnin(10000) chain(5000)) initsb(b) nopause 
But it gives me very strange results (no matter the burnin and chain parameters). Main point is that I have the value of the constant of 42.8. Cohort residuals range between -2.8 and -3 and period residuals range between -38 and -39.
I am struggling about the reasons.

I have also run the same model using xtmixed

Code: Select all

xtmixed attendp ager || _all: R.cohort_cat || _all: R.period_cat 
Here the cons is 0.46, cohort residuals range between 0.1 and -0.1 and period residuals range between 0.16 and -0.23 which seem fine to me. The correlation between mcmc residuals and xtmixed residuals is close to 1.

Any suggestion about how to implemente my model using runmlwin?

Thanks in advance


Post Reply