Announcement

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

  • I can not calculate the "margin" for one of the terms of an sex variable

    Hello,

    I am looking to model the marginal effect of increasing screen time (ppost_12) on the flourish score.
    I am looking to model this as a function of sexe/variable "sex5" (for which female = 1 or male =2).
    I am also looking to see if this marginal effect as a function of sexe varies according to whether the person is in the top 25 percentile of flourish, between the 25th and 75th percentile or if they are after the 75th percentile.

    [CODE]
    //ppost_12_25 percentile
    preserve
    summarize flourish, detail
    local qa = r(p25)
    keep if flourish <`qa'
    glm flourish c.ppost_12##c.ppost_12##c.ppost_12##i.sex5 i.ageqx i.ses, vce(cluster schoolid)
    estimate store mglm
    margins, over(sex5) at(ppost_12 =(0(30)180)) contrast(atcontrast(r)) vce(unconditional) saving(marg_ppost12_25_sexe, replace)
    restore

    //ppost_12_25-75 percentile
    preserve
    fre flourish
    summarize flourish, detail
    local qa = r(p25)
    local qb = r(p75)
    keep if flourish >`qa' & flourish <`qb'
    glm flourish c.ppost_12##c.ppost_12##c.ppost_12##i.sex5 i.ageqx i.ses, vce(cluster schoolid)
    estimate store mglm
    margins, over(sex5) at(ppost_12 =(0(30)180)) contrast(atcontrast(r)) vce(unconditional) saving(marg_ppost12_2575_sexe, replace)
    restore

    //ppost_12_75 percentile
    preserve
    fre flourish
    summarize flourish, detail
    local qb = r(p75)
    keep if flourish >`qb'
    glm flourish c.ppost_12##c.ppost_12##c.ppost_12##i.sex5 i.ageqx i.ses, vce(cluster schoolid)
    estimate store mglm
    margins, over(sex5) at(ppost_12 =(0(30)180)) contrast(atcontrast(r)) vce(unconditional) saving(marg_ppost12_75_sexe, replace)
    restore


    combomarginsplot marg_ppost12_25_sexe marg_ppost12_2575_sexe marg_ppost12_75_sexe, xdim(ppost_12) xlab(30(30)180) ylab(-4(.5).5,angle(horizontal)) yline(0) recast(scatter) name(marg_ppost_sexe, replace) plotopts(msize(small)) ciopts(lwidth(thin))
    [CODE]

    My problem :
    Stata tells me that it is not possible to estimate the values for the ‘female’ category between the 25th and 75th percentiles after margins. I realised it was because stata couldn't estimate for the 0 value of ppost (ony for the ‘female’ category between the 25th and 75th percentiles) although there are observations for this modality.
    Ps: when I do "recode ppost_12 (0 = 1)" and perform my margin "at(ppost_12 =(1,30,60,90,120,150,180))", it works.


    I hope I have made myself clear, but thank you very much in advance for your help.

  • #2
    test

    Comment

    Working...
    X