Refering this post, https://stats.oarc.ucla.edu/stata/fa...irect-effects/
I wrote the code below, what's wrong for the code since it cannnot work well.
I wrote the code below, what's wrong for the code since it cannnot work well.
Code:
sysuse auto,clear set seed 10000 capture program drop ModMed program define ModMed, rclass quietly summarize gear_ratio return list global m=r(mean) global sd=r(sd) reg price mpg c.length##c.gear_ratio generate IV = rnormal(_b[c.length],_se[c.length]) generate Mod = rnormal(_b[c.length#c.gear_ratio],_se[c.length#c.gear_ratio]) reg weight price mpg c.length generate Med = rnormal(_b[price],_se[price]) end simulate indL=(((IV+Mod*($m-$sd)))*(Med)) indM=(((IV+Mod*($m)))*(Med)) indH=(((IV+Mod*($m+$sd)))*(Med)), reps(50) seed(1234): ModMed ci means indL indM indH

Comment