I hope this message finds everyone well. I am currently running some Difference-in-difference analysis (DiD) in Stata/MP 15.1. My data set has two time points: pre-test and post-test. It also has a treated group and a control group. The data are set-up in the long format.
I am trying to do some path analysis of how my treatment affects someone's happiness via its effect on their number of friends (the indirect-effect), using Stata's GSEM command. I then want to look at whether the impact of the treatment on happiness via number of friends is conditional on someone's level of disadvantage - what I think is a moderated mediation test. So, the outcome I am interested in is 'happiness'. The mediator I am interested in is 'number of friends'. The moderator I am interested in is an individual's level of 'disadvantage'.
I am hoping to find out if my current approach to this is correct, and to ask some specific questions if possible.
The variables are described here:
time: time (binary): 0 (pre-test) and 1 (post-test)
treatment: treated (binary): 0 (control) and 1 (treated)
outcome: happy (continuous): 0-11
mediator: nfriends (continuous): 0-10
moderator: disadvantage (continuous): 0 to 55.7
id: personal identifier
weight: is a weight variable accounting for attrition
The data are set-up in long format and set to panel data:
Code:
xtset id time
Code:
gsem (nfriend <- i.time##i.treatment M1[id])(happy<- i.time##i.treatment nfriend M2[id]) [pw=weight], vce(robust) cov(M1[id]*M2[id]@0)
Code:
nlcom
Code:
nlcom [nfriend]_b[1.time#1.treatment]*[happy]_b[nfriend]
The second step has been to look at whether the effect of the treatment on happiness via number of friends is conditional someone's level of disadvantage. To test this I include an interaction-term between i.time##i.treatment##c.disadvantage:
Code:
gsem (nfriend <- i.time##i.treatment##c.disadvantage M1[id])(happy <- i.time##i.treatment##c.disadvantage nfriend M2[id]) if nms==0 [pw=weight], vce(robust) cov(M1[id]*M2[id]@0)
Indirect-effect at lowest (0.7) disadvantage:
Code:
nlcom (_b[nfriend:1.time#1.treatment#c.disadvantage]+0.7*_b[nfriend:1.time#1.treatment#c.disadvantage])*_b[happy:nfriend]
Code:
nlcom (_b[nfriend:1.time#1.treatment#c.disadvantage]+55.7*_b[nfriend:1.time#1.treatment#c.disadvantage])*_b[happy:nfriend]
I hope this is clear and the code comes out correctly (first time poster). Thanks so much in advance for your help.
James
0 Response to Moderated mediation using GSEM from a difference-in-difference approach - calculating ini
Post a Comment