Dear Stata forum,
I would like to estimate a mediation model using the first difference estimator. I know that the user-written xtdpdml command from Williams, Allison and Moral Benito exists but as far as I understand, it is not possible to use this command for mediation analysis. Therefore, I need to specify the first difference estimator using Stata's sem command.
However, I am not sure how to code the first difference estimator using Stata's sem command. I have not found any examples in the manual, nor on the Statalist forum. In particular, the first difference estimator assumes sequential exogeneity. I tried to correctly specify this assumption based on the code and using the same dataset as explained in Allison, P. D., Williams, R., & Moral-Benito, E. (2017). Maximum likelihood for cross-lagged panel models with fixed effects. Socius, 3, 2378023117710578 in which they code a cross-lagged panel data model (which also assumes sequential exogeneity). However, my first difference estimator does not converge.
This is my code for the first difference estimator using the online available dataset. I also estimated the model using the reg command for comparison (both estimations should be in the same range of magnitude).
Does anyone know if the above code of the first difference estimator with Stata's sem command is correct? I have also tried the code with other datasets, which also do not converge, so I think the problem is with an incorrect specification rather than a pure non-convergence problem.
Any suggestions would be appreciated.
Kind regards,
Eva
I would like to estimate a mediation model using the first difference estimator. I know that the user-written xtdpdml command from Williams, Allison and Moral Benito exists but as far as I understand, it is not possible to use this command for mediation analysis. Therefore, I need to specify the first difference estimator using Stata's sem command.
However, I am not sure how to code the first difference estimator using Stata's sem command. I have not found any examples in the manual, nor on the Statalist forum. In particular, the first difference estimator assumes sequential exogeneity. I tried to correctly specify this assumption based on the code and using the same dataset as explained in Allison, P. D., Williams, R., & Moral-Benito, E. (2017). Maximum likelihood for cross-lagged panel models with fixed effects. Socius, 3, 2378023117710578 in which they code a cross-lagged panel data model (which also assumes sequential exogeneity). However, my first difference estimator does not converge.
This is my code for the first difference estimator using the online available dataset. I also estimated the model using the reg command for comparison (both estimations should be in the same range of magnitude).
Code:
/*==========================================================================================*\ | Implementation of ML-SEM for the first difference estimator | Data described by Cornwell and Rupert (1988) for 595 household heads who reported a non-zero | wage in each of 7 years from 1976 to 1982 | Dependent variable: wks (number of weeks employed in each year) | Independent variable: union (dummy equalling 1 if wage set by union contract in each year) | Control variable: lwage (log of wage in each year) | xtdpdml and sem: method mlmv to equal the outcome of the reg command | Stata version 17.0 \*==========================================================================================*/ ************************** estimations using sem ******************************* ** import the dataset use https://www3.nd.edu/~rwilliam/statafiles/wages, clear keep wks lwage union id t ** specify the first differences manually foreach x of varlist wks lwage union { gen d1`x'=D.`x' /* x_i,t - x_i,t-1 */ } ** reshape the data to wide format reshape wide wks d1wks lwage d1lwage union d1union, i(id) j(t) ** first difference estimation: this model does not converge sem (d1wks1 <- d1lwage1@b2 d1union1@b3 Alpha@1 E1@1) /// (d1wks2 <- d1lwage2@b2 d1union2@b3 Alpha@1 E2@1) /// (d1wks3 <- d1lwage3@b2 d1union3@b3 Alpha@1 E3@1) /// (d1wks4 <- d1lwage4@b2 d1union4@b3 Alpha@1 E4@1) /// (d1wks5 <- d1lwage5@b2 d1union5@b3 Alpha@1 E5@1) /// (d1wks6 <- d1lwage6@b2 d1union6@b3 Alpha@1 E6@1) /// (d1wks7 <- d1lwage7@b2 d1union7@b3 Alpha@1), /// var(e.d1wks1@0 e.d1wks2@0 e.d1wks3@0 e.d1wks4@0 e.d1wks5@0 e.d1wks6@0) ///sequential exogeneity assumption: error term may be correlated with future values of time-dependent predictors. In sem, the only solution to do this is to suppress the original error terms by setting their variances equal to zero and introducing new latent error terms E1-E6. There is no need to do that at time 7 because there is no future value of union in the model. cov(Alpha*(E1 E2 E3 E4 E5 E6)@0) ///sets the covariance between the unit-specific time-constant error term (Alpha) and the time-varying error term (E*) to zero cov(_OEx*(E1 E2 E3 E4 E5 E6)@0) ///sets the covariances between all of the observed exogenous variables (_OEx*) and the new error terms (E*) equal to zero cov(E1*(E2 E3 E4 E5 E6)@0) cov(E2*(E3 E4 E5 E6)@0) cov(E3*(E4 E5 E6)@0) cov(E4*(E5 E6)@0) cov(E5*(E6)@0) ///constrains all the new error terms (E*) to be uncorrelated with each other cov((d1lwage2 d1union2)*(E1)) cov((d1lwage3 d1union3)*(E1 E2)) cov((d1lwage4 d1union4)*(E1 E2 E3)) cov((d1lwage5 d1union5)*(E1 E2 E3 E4)) cov((d1lwage6 d1union6)*(E1 E2 E3 E4 E5)) cov((d1lwage7 d1union7)*(E1 E2 E3 E4 E6)) ///sequential exogeneity assumption: allow the new error terms to be correlated with future values of the predetermined predictors, union and lwage method(mlmv) ************** estimations using reg for comparison ************************ ** import the dataset use https://www3.nd.edu/~rwilliam/statafiles/wages, clear keep wks lwage union id t ** specify the data as panel data xtset id t ** first difference estimation gen year1=1 if t==1 replace year1 = 0 if missing(year1) gen year2=1 if t==2 replace year2 = 0 if missing(year2) gen year3=1 if t==3 replace year3 = 0 if missing(year3) gen year4=1 if t==4 replace year4 = 0 if missing(year4) gen year5=1 if t==5 replace year5 = 0 if missing(year5) gen year6=1 if t==6 replace year6 = 0 if missing(year6) gen year7=1 if t==7 replace year7 = 0 if missing(year7) reg D.wks D.lwage D.union D.year2 D.year3 D.year4 D.year5 D.year6 D.year7, nocons
Any suggestions would be appreciated.
Kind regards,
Eva
Comment