Announcement

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

  • Mediation analysis for a lagged, quadratic panel model



    Hi,

    My model is on a panel data.
    y(t+2) = a + b.indep_var(t) + c.indep_var_sq(t) + controls(t)
    It is a non-linear (concave) relationship based on correlated random effects using Mundlak's approach. I need to test for mechanism design using mediation analysis.

    Have checked other posts on the forum but could not find the answer as these discuss cross sectional data using mediate package and not a panel data with lead-lagged models.

    Please suggest how to conduct this kind of analysis. Thanks.

  • #2
    This is strong maybe, but might get you started.



    Code:
    ssc install combomarginsplot
    
    webuse nlswork, clear
    xtset idcode year
    
    g tenure2 = tenure*tenure
    egen mean_tenure = mean(tenure) , by(idcode)
    egen mean_tenure2 = mean(tenure2) , by(idcode)
    center mean_tenure2, generate(mean_tenure2c)
    
    xtreg ln_wage c.tenure##c.tenure mean_tenure mean_tenure2c , re
    margins, dydx(tenure)
    margins, at(tenure=(0(1)25)) saving(m1, replace)
    marginsplot
    
    xtreg ln_wage c.tenure##c.tenure age mean_tenure mean_tenure2c , re
    margins, dydx(tenure)
    margins, at(tenure=(0(1)25)) saving(m2, replace)
    marginsplot
    
    combomarginsplot m1 m2 , labels("Basic Model" "Mediated Model")
    
    xtreg age c.tenure##c.tenure mean_tenure mean_tenure2c , re
    capture drop age_fit
    predict age_fit, xbu
    
    xtreg ln_wage c.tenure##c.tenure age_fit mean_tenure mean_tenure2c , re vce(bootstrap, reps(100))
    margins, dydx(tenure)
    margins, at(tenure=(0(1)25)) saving(m3, replace)
    marginsplot
    
    combomarginsplot m1 m2 m3 , labels("Basic Model" "Mediated Model" "Mediated Prediction")

    Comment


    • #3
      probably should include mean_age in second regression.

      The predicted model presents problems if you include mean_age_fit

      Code:
      webuse nlswork, clear
      xtset idcode year
      
      g tenure2 = tenure*tenure
      egen mean_tenure = mean(tenure) , by(idcode)
      egen mean_tenure2 = mean(tenure2) , by(idcode)
      center mean_tenure2, generate(mean_tenure2c)
      egen mean_age = mean(age) , by(idcode)
      
      xtreg ln_wage c.tenure##c.tenure mean_tenure mean_tenure2c , re
      margins, dydx(tenure)
      margins, at(tenure=(0(1)25)) saving(m1, replace)
      marginsplot
      
      xtreg ln_wage c.tenure##c.tenure age mean_tenure mean_tenure2c mean_age, re
      margins, dydx(tenure)
      margins, at(tenure=(0(1)25)) saving(m2, replace)
      marginsplot
      
      combomarginsplot m1 m2 , labels("Basic Model" "Mediated Model") 
      
      xtreg age c.tenure##c.tenure mean_tenure mean_tenure2c , re
      capture drop age_fit
      predict age_fit , xbu
      egen mean_age_fit = mean(age_fit) , by(idcode)
      
      xtreg ln_wage c.tenure##c.tenure age_fit mean_tenure mean_tenure2c , re vce(bootstrap, reps(100))
      margins, dydx(tenure)
      margins, at(tenure=(0(1)25)) saving(m3, replace)
      marginsplot
      
      combomarginsplot m1 m2 m3 , labels("Basic Model" "Mediated Model" "Mediated Prediction")

      Comment


      • #4
        HTML Code:
        https://www.researchgate.net/publication/315474646_Incorporating_nonlinearity_into_mediation_analyses

        Comment

        Working...
        X