Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Graphing age and period main effects derived from mixed-effects logit model

    Hello Everyone,

    I am estimating an age-period-cohort (APC) model to isolate cohort trends in diabetes (0=does not have diabetes, 1=has diabetes) by using a mixed model framework specifying cohort at level 1 and period and age at level 2 such that they are not linear combinations. This method I am using is based on Yang Y, Land KC. Age-Period-Cohort Analysis: New Models, Methods, and Empirical Applications. New York: Chapman and Hall/CRC; 2013.

    Code:
    meqrlogit diabe i.cohort  || _all:R.period || agecat:, var or
    I want to use the estimates from this model to produce two figures: 1) where age is on the x-axis, and 2) where period is on the x-axis. The y-axis is supposed to be the diabetes prediction. The lines are supposed to be each cohort group.

    Here's an example of what I want to produce (I am interested in the first two graphs):
    Click image for larger version

Name:	APC main effects estimates.PNG
Views:	1
Size:	102.8 KB
ID:	1530575




    Source: https://conservancy.umn.edu/bitstrea...=1&isAllowed=y

    In searching the forum, I have found a dearth of threads that address APC models, and the ones that do exist have not addressed creating these type of graphs.

    From what I have gathered from the forum and Google searching, I believe I need the following pieces:
    Code:
    // predict fixed part
    predict pfx, xb
    
    // predict random effects
    predict v0*, reffects  
    
    // predict standard errors
    predict v0se*, reses
    
    
    // Period Probability
    gen probPeriod = 1 /(1+exp(-1*(pfx + v01)))
    *95% CI
    gen probPrL = probPeriod-1.96*v0se1
    gen probPrU = probPeriod+1.96*v0se1
    
    // Age Probability
    gen probAge = 1 /(1+exp(-1*(pfx + v02)))
    *95% CI
    gen probArL = probAge-1.96*v0se2
    gen probArU = probAge+1.96*v0se2
    I have tried using the twoway graph functions and was able to generate an overall period graph:
    Code:
    preserve
    collapse (mean) probP = probPeriod (semean) probPs = probPeriod, by(period)
    gen probPrL = probP-1.96*probPs
    gen probPrU = probP+1.96*probPs
     
    twoway (connected probP period, mcolor(black) lcolor(black)) ///
    (connected probPrL period, mcolor(black) lcolor(black) lpattern(dash)) ///
    (connected probPrU period, mcolor(black) lcolor(black) lpattern(dash)), ///
    ytitle(Predicted probability with 95% confidence band) xtitle(Period) xlabel(#3) legend(off)
    
    restore
    I've been trying to figure out how to manipulate this code in order to get cohorts in the lines and diabetes as the y-axis; however, I have exhausted whatever knowledge and Google search skills I have.

    I have also been wondering if it is a possibility to use the margins & marginsplot commands to get what I want.

    I appreciate you all for reading this and look forward to anyone that may be able to help me learn how to do this.

    EDIT: I forgot to include that I am using Stata version 16.
    Last edited by Catherine Garcia; 02 Jan 2020, 22:57.

  • #2
    UPDATE: Here is the progress I have made to get the graph I am interested in. After reading Bell and Jones (2015), I refined my model to reflect that my cohort variable was entered in the model as a fixed and random effect, and that age and age-squared should be as part of the fixed effect (I centered my age variable). Cohorts were grouped into 5-year intervals in the random part of the model, to account for the autocorrelation between cohort years, while I kept the cohort groups I am mainly interested in in the fixed part of the model.

    Code:
    // mixed-effects logit model
    meqrlogit diabe i.mycohort ageC##ageC  || _all:R.period || cohort:, var or
    Here are the calculations made by predict:
    Code:
    // predict fixed part
    predict pfx, xb
    
    // predict random effects
    predict v0*, reffects  
    
    // predict standard errors
    predict v0se*, reses
    
    // Period Probability
    gen probPeriod = 1 /(1+exp(-1*(pfx + v01)))
    *95% CI
    gen probPrL = probPeriod-1.96*v0se1
    gen probPrU = probPeriod+1.96*v0se1
    Here is the setup to get towards the graph I am interested in:

    Code:
    preserve
    
    collapse (mean) probP = probPeriod (semean) probPs = probPeriod, by(period mycohort)  //notice that I collapsed by year and cohort
     
    twoway (connected probP period if mycohort==1, mcolor(gold) lcolor(gold)) ///
                 (connected probP period if mycohort==2, mcolor(green) lcolor(green)) ///
                 (connected probP period if mycohort==3, mcolor(black) lcolor(black)) ///
                 (connected probP period if mycohort==4, mcolor(blue) lcolor(blue)) ///
                 (connected probP period if mycohort==5, mcolor(red) lcolor(red)) ///
                 (connected probP period if mycohort==6, mcolor(purple) lcolor(purple)) ///
                 (connected probP period if mycohort==7, mcolor(magenta) lcolor(magenta)), ///
                 ytitle(Predicted probability with 95% confidence band) xtitle(Period) xlabel(#3) legend(off)
    
    restore
    Note that I haven't included the 95% confidence intervals in the graph; that's the next step.

    If anyone can provide feedback, I'd greatly appreciate it.
    Last edited by Catherine Garcia; 03 Jan 2020, 14:41.

    Comment


    • #3
      Have you gotten any further with your ideas of age-period-cohort analyses? I am currently looking into APC, but I'm still a complete novice. I haven't even made up my mind about whether to use R or Stata.

      BTW, I think it is crucial to consider criticism of traditional APC and Yang and Land, which you obviously do, as you refer to Bell and Jones (2015).

      Comment

      Working...
      X