Age-Cohort-Period Effect by Country / HAPC, runmlwin

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 >> http://www.bristol.ac.uk/cmm/software/runmlwin/
Post Reply
KazimovHH
Posts: 14
Joined: Mon Apr 09, 2018 11:56 am

Age-Cohort-Period Effect by Country / HAPC, runmlwin

Post by KazimovHH » Mon Jan 21, 2019 12:29 pm

Dear Community,

I am trying to plot the cohort group effect by country after estimating Hierarchical Age Period Cohort Model (HAPC):

This is the model - binary outcome variable with four levels (country, cohort group, period and individuals), cross-classified:

Code: Select all

	sort cntry_n cohortgrp essround ind
	runmlwin vote cons age_cen age_censq, ///
		level4(cntry_n: cons) ///
		level3(cohortgrp: cons) ///
		level2(essround: cons) /// 
		level1(ind:) ///
		discrete(distribution(binomial) link(logit) denom(cons) pql2)
	
	display "`c(current_time)' `c(current_date)'"		
	runmlwin vote cons age_cen age_censq, ///
		level4(cntry_n: cons, residuals(k)) ///
		level3(cohortgrp: cons, residuals(v)) ///
		level2(essround: cons, residuals(u)) /// 
		level1(ind:) ///
		discrete(distribution(binomial) link(logit) denom(cons)) ///
		mcmc(cc burnin(5000) chain(500000) hcen(3)) initsprevious nopause nogroup	
	display "`c(current_time)' `c(current_date)'"		

	
	save hapc, replace
	estimates save hapc, replace
Then I plot the cohort group effect (based on the Bell&Jones (2017) HAPC):

Code: Select all


egen pickone = tag(cohortgrp)
	
	mat A = e(b)
	scalar B = A[1,1] 
	gen newv0 = v0 + B
	replace newv0 = invlogit(newv0)
	gen newv0seHI = v0 + B + (1.96*v0se)
	gen HIv0= invlogit(newv0seHI)
	gen newv0seLO = v0 + B - (1.96*v0se)
	gen LOv0= invlogit(newv0seLO)
	
	sort cohort
	twoway (line newv0 cohortgrp if pickone==1) ///
	(line LOv0 cohortgrp if pickone==1, lpattern(dash)) ///
	(line HIv0 cohortgrp if pickone==1, lpattern(dash)), ///
	legend(off) scheme(s2mono) graphregion(color(white)) ///
	ytitle("") xtitle("Birth Year") ///
	xscale(range(1900 2000)) yscale(range(0.7 0.8)) ///
	xlabel(1909(20)1990) ylabel(0.5(0.1)0.8)

	graph save hacp_cohortgrp, replace 
Here is the plot:
hacp_cohortgrp.png
Cohort Group Effect
hacp_cohortgrp.png (58.08 KiB) Viewed 888 times
Afterwards, I try to plot by country simply adding the "by country, compact" to the twoway code:

Code: Select all

sort cohort
	twoway (line newv0 cohortgrp if pickone==1, by(cntry, compact)) ///
	(line LOv0 cohortgrp if pickone==1, lpattern(dash)) ///
	(line HIv0 cohortgrp if pickone==1, lpattern(dash)), ///
	legend(off) scheme(s2mono) graphregion(color(white)) ///
	ytitle("") xtitle("Birth Year") ///
	xscale(range(1900 2000)) yscale(range(0.7 0.8)) ///
	xlabel(1909(20)1990) ylabel(0.5(0.1)0.8)
Here is the plot by country:
hacp_cohortgrp_cntry.png
Cohort Group Effect by Country
hacp_cohortgrp_cntry.png (72.88 KiB) Viewed 888 times

However, it shows only one country. Please share your suggestions.

Looking forward.
Regards,
Rza

ChrisCharlton
Posts: 1099
Joined: Mon Oct 19, 2009 10:34 am

Re: Age-Cohort-Period Effect by Country / HAPC, runmlwin

Post by ChrisCharlton » Tue Jan 22, 2019 4:19 pm

Can you confirm that there is data present for the other countries when you issue the plot command? Maybe you could create some summary tables using the same filtering. If they are there you could try plotting simpler versions of the charts to check that they work as expected.

Post Reply