Announcement

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

  • Margins with random effects

    Hello,

    I am estimating a three-level random intercept logit model using xtmelogit (meqrlogit). Ideally I would like to obtain the marginal effects as we do with the command margins. I have read that margins only takes into account the fixed part and not the random effects. I would like to obtain a similar result as using margins but including random effects.

    In this sense, I have tried the code below but find that the following error message comes up: "data have changed since estimation". I have done a small test-run on a simple logit model to test whether the code was ok, this is I am able to obtain the same results obtaining the margins myself as I do using the command 'margins' and it seems work ok.

    I believe the error might come from the stochastic nature of the random effects. I am not certain whether it makes sense to aim at obtaining the margins with the random effects in in this manner or if it has to be done in another fashion. I found a close post in Stata FAQ http://www.ats.ucla.edu/stat/stata/f...logit_prob.htm

    My dependent variable is participation on a treatment and say the independent variable is the categorical variable employment (Self-Employed, Employed, Retired, Students, Other Non-active).

    On a second question related to this one, once I estimate successfully the predictions with the random effects, what would be the appropriate way of contrasting whether the margins estimated are significantly different from each other in a similar way as what we can do with margins, contrast?

    Thanks in advance,

    Code:
     ** PART 1: Simple example: Use Logit (no random effects)
    
    logit part i.employment
    margins employment
    
    * Replicate the result of "margins employment"
    clonevar emp=employment
    logit particip i.emp
    forval i=1/5{
    replace emp=`i'
    predict adjpred`i'
    }
    sum adjpred*
    
    *Replicates the result of "margins, dydx(employment)"
    gen meemp2=adjpred2-adjpred1
    gen meemp3=adjpred3-adjpred1
    gen meemp4=adjpred4-adjpred1
    gen meemp5=adjpred5-adjpred1
    
    sum meemp2 meemp3 meemp4 meemp5
    
    ** PART 2: Using the model my three-level model with random intercept at the country and regional level.
    
    xtmelogit particip i.empl || countries: || coren:, cov(unstructured)variance intpoints(5)  
    margins i.empl
    
    clonevar emply=empl
    xtmelogit particip i.emply || countries: || coren:, cov(unstructured)variance intpoints(5)  
    
    * After this point we get the error message: "data have changed since estimation"
    
    forval i=1/5{
    xtmelogit
    replace emply=`i'
    predict adjpred`i'
    }
    
    * Obtain the same result as margins, dydx(employment)
    
    gen meempl2=adjpred2-adjpred1
    gen meempl3=adjpred3-adjpred1
    gen meempl4=adjpred4-adjpred1
    gen meempl5=adjpred5-adjpred1
    
    sum adjpred* meempl2 meempl3 meempl4 meempl5
Working...
X