capture log close log using cervix, text replace set more off version 8.1 /* Stata do-file for some of the analysis of Section 14.3 of Skrondal, A. and Rabe-Hesketh, S (2004). Generalized Latent Variable Modeling. Multilevel, Longitudinal and Structural Equation Models. Chapman & Hall/CRC */ * Read data infile D X W using cervix.dat, clear * Estimates using true exposure only in validation sample logit D X if X~= -9 * Estimates using imperfect measure of exposire logit D W * Estimate joint model using gllamm * Collapse and reshape data: gen cons=1 collapse (sum) wt2=cons, by(D X W) gen patt=_n list patt D X W wt2, clean * Stack responses X,W,D into variable y and create a key to which * response is of which type, var=1,2,3, respectively gen y1 = X gen y2 = W gen y3 = D reshape long y, i(patt) j(var) drop if y==-9 * Dumies for the three response types: tab var, gen(d) * Dummy for being in the validation sample: gen v = X> -9 gen nv = 1-v * Interactions between variables and dummies for fixed part gen v_d1 = v*d1 gen X_v_d2 = X*v*d2 gen D_v_d2 = D*v*d2 gen D_nv_d2 = D*nv*d2 gen X_D_v_d2 = X*D*v*d2 gen X_v_d3 = X*v*d3 * Intercations between variables and dummies for random part gen nv_d2 = nv*d2 * already defined: gen D_nv_d2 = D*nv*d2 gen nv_d3 = nv*d3 cons def 1 [z2_1_1]nv_d2=1 cons def 2 [z2_1_2]nv_d2=0 cons def 3 [pat1_1l]nv_d2 = [y]X_v_d2 cons def 4 [pat1_1l]D_nv_d2=[y]X_D_v_d2 cons def 5 [pat1_1l]nv_d3=[y]X_v_d3 cons def 6 [y]d1=[p2_1]_cons * Non-differential measurement error (alpha_2=alpha_3=0) eq load: nv_d2 nv_d3 gllamm y d1 d2 X_v_d2 d3 X_v_d3, i(patt) l(logit) f(binom) nocons nip(2) /* */ ip(fn) eqs(load) constr(1 2 3 5 6) frload(1) weight(wt) * Response probabilities gllapred mu, mu * Probabilities of W for given X and D (Table 14.4): list X D mu if v==1&d2==1, clean * Posterior probabilities of true exposure X (Table 14.5) gllapred p, p sort patt list W D p1 p2 if nv==1, clean drop p1 p2 mu /* differential measurement error */ eq load: nv_d2 D_nv_d2 nv_d3 gllamm y d1 d2 X_v_d2 D_v_d2 D_nv_d2 X_D_v_d2 d3 X_v_d3, i(patt) l(logit) f(binom) nocons nip(2) /* */ ip(fn) eqs(load) constr(1 2 3 4 5 6) frload(1) weight(wt) * Response probabilities gllapred mu, mu * Probabilities of W for given X and D (Table 14.4): list X D mu if v==1&d2==1, clean * Posterior probabilities of true exposure X (Table 14.5) gllapred p, p sort patt list W D p1 p2 if nv==1, clean drop p1 p2 mu log close exit