Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 72767

Generating lagged variables in mi data

$
0
0
I'm having trouble generating lagged variables in mi data. Here is an example where students are tested in reading and math at 3 different times, and I try to generate a variable that lags the scores by one period. I'm trying to follow the advice posted by Stata's Yulia Marchenko in http://www.stata.com/statalist/archi.../msg00213.html . If you look at the output, though, you'll see that the lagged variables are calculated from the observed data, not from the imputed data as I intended.

/* First I impute the data in wide format to account for the correlations among tests. Then I reshape the imputed data into long format again.
This works fine. I'm just including it so that we have some data to work with. */
use "http://www.ats.ucla.edu/stat/stata/faq/mi_longi.dta", clear
reshape wide read math, i(id) j(time)
order *, sequential
mi set wide
mi register imputed math1-math3 read1-read3
mi impute mvn math1-math3 read1-read3, add(2)
mi reshape long math read, i(id) j(time)

/* Now I try to calculate the lagged variables. This is what isn't working for me. */
mi tsset id time
mi xeq: sort id time; gen math_lag = L1.math; gen read_lag = L1.read
list in 1/3




Viewing all articles
Browse latest Browse all 72767

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>