Hi Jerry. I haven't tried constraints but I believe they can work. Specifying them is not as straightforward as what you wrote though.
Consider this example:
The data set is in long format. wks, lwage, and union are time varying, while ed is time invariant.
xtdpdml reshapes the data from long to wide, so sem can analyze it with sem. After reshaping, the time-varying variables have names like wks2, wks3, lwage1, lwage2, union4, union5, etc. The time-invariant ed is just called ed.
So, the problem with a constraints command is that the variable names aren't right once the data are reshaped wide. Further complicating things is that the reshaped var names depend on your lag structure. Also, you might have lag 2 and lag 3 versions of a variable in a model -- which would you want constrained?
So, I would probably do something like this:
and then I would hand-edit xtest.do with the constraints I want, e.g. set the effects of lagged union equal to 1:
There are probably other and maybe easier ways to do this, but this seems like a relatively straightforward way to me. If there were huge demand for such a feature I might see if there are easier ways to program it.
But in general, if xtdpdml can't quite do what you want, letting it generate the code to get you started and then tweaking it will sometimes solve your problem.
Consider this example:
Code:
. use https://www3.nd.edu/~rwilliam/statafiles/wages, clear . xtset id t Panel variable: id (strongly balanced) Time variable: t, 1 to 7 Delta: 1 unit . quietly xtdpdml wks L.lwage, inv(ed) pre(L.union) ti(Baseline Model) semfile(xtest, r) . type xtest.do #delimit ; sem (wks2 <- wks1@b1 lwage1@b2 union1@b3 ed@b4 Alpha@1 E2@1 ) (wks3 <- wks2@b1 lwage2@b2 union2@b3 ed@b4 Alpha@1 E3@1 ) (wks4 <- wks3@b1 lwage3@b2 union3@b3 ed@b4 Alpha@1 E4@1 ) (wks5 <- wks4@b1 lwage4@b2 union4@b3 ed@b4 Alpha@1 E5@1 ) (wks6 <- wks5@b1 lwage5@b2 union5@b3 ed@b4 Alpha@1 E6@1 ) (wks7 <- wks6@b1 lwage6@b2 union6@b3 ed@b4 Alpha@1 ), var(e.wks2@0 e.wks3@0 e.wks4@0 e.wks5@0 e.wks6@0) var(Alpha) cov(Alpha*(ed)@0 Alpha*(E2 E3 E4 E5 E6)@0 _OEx*(E2 E3 E4 E5 E6)@0 E2*(E3 E4 E5 E6)@0 E3*(E4 E5 E6)@0 E4*(E5 E6)@0 E5*(E6)@0 union3*(E2) union4*(E2 E3) union5*(E2 E3 E4) union6*(E2 E3 E4 E5)) iterate(250) technique(nr 25 bhhh 25) noxconditional; #delimit cr
xtdpdml reshapes the data from long to wide, so sem can analyze it with sem. After reshaping, the time-varying variables have names like wks2, wks3, lwage1, lwage2, union4, union5, etc. The time-invariant ed is just called ed.
So, the problem with a constraints command is that the variable names aren't right once the data are reshaped wide. Further complicating things is that the reshaped var names depend on your lag structure. Also, you might have lag 2 and lag 3 versions of a variable in a model -- which would you want constrained?
So, I would probably do something like this:
Code:
xtdpdml wks L.lwage, inv(ed) pre(L.union) ti(Baseline Model) semfile(xtest, r) dryrun staywide
Code:
#delimit ; sem (wks2 <- wks1@b1 lwage1@b2 union1@1 ed@b4 Alpha@1 E2@1 ) (wks3 <- wks2@b1 lwage2@b2 union2@1 ed@b4 Alpha@1 E3@1 ) (wks4 <- wks3@b1 lwage3@b2 union3@1 ed@b4 Alpha@1 E4@1 ) (wks5 <- wks4@b1 lwage4@b2 union4@1 ed@b4 Alpha@1 E5@1 ) (wks6 <- wks5@b1 lwage5@b2 union5@1 ed@b4 Alpha@1 E6@1 ) (wks7 <- wks6@b1 lwage6@b2 union6@1 ed@b4 Alpha@1 ), var(e.wks2@0 e.wks3@0 e.wks4@0 e.wks5@0 e.wks6@0) var(Alpha) cov(Alpha*(ed)@0 Alpha*(E2 E3 E4 E5 E6)@0 _OEx*(E2 E3 E4 E5 E6)@0 E2*(E3 E4 E5 E6)@0 E3*(E4 E5 E6)@0 E4*(E5 E6)@0 E5*(E6)@0 union3*(E2) union4*(E2 E3) union5*(E2 E3 E4) union6*(E2 E3 E4 E5)) iterate(250) technique(nr 25 bhhh 25) noxconditional; #delimit cr
But in general, if xtdpdml can't quite do what you want, letting it generate the code to get you started and then tweaking it will sometimes solve your problem.
Comment