I have a piece of code for estimation generalized ordered probit model from the book A.M.Jones (2007) Applied Econometrics for Health Economists (Ch.4 Bias in sell-reported data).
I use Stata 14.2. This code works fine:
Code:
reshape long vig_mobility_, i(id) j(vignum) tabulate vignum, generate(vigdum) drop vigdum1 /* Program for GOP - cutpoints are functions of individual characteristics, health index function of vignette dummies */ cap program drop gop program define gop args lnf b m1 m2 m3 m4 tempvar p1 p2 p3 p4 p5 quietly { gen double `p1' = 0 gen double `p2' = 0 gen double `p3' = 0 gen double `p4' = 0 gen double `p5' = 0 replace `p1' = normal(`m1'-`b') replace `p2' = normal(`m2'-`b') - normal(`m1'-`b') replace `p3' = normal(`m3'-`b') - normal(`m2'-`b') replace `p4' = normal(`m4'-`b') - normal(`m3'-`b') replace `p5' = 1 - normal(`m4'-`b') replace `lnf' = (vig_mobility_==1)*ln(`p1')+(vig_mobility_==2)*ln(`p2')+(vig_mobility_==3)*ln(`p3')+(vig_mobility_==4)*ln(`p4')+(vig_mobility_==5)*ln(`p5') } end *** Estimate GOP for the vignettes *** ml model lf gop (xb: vigdum*, nocons) (mu1: $cvars) (mu2: $cvars) (mu3: $cvars) (mu4: $cvars) if vig_mobility_!=. ml search ml maximize drop vigdum* reshape wide vig_mobility_, i(id) j(vignum)
Code:
cap program drop gop program define gop args lnf b m1 m2 m3 m4 tempvar p1 p2 p3 p4 p5 quietly { gen double `p1' = 0 gen double `p2' = 0 gen double `p3' = 0 gen double `p4' = 0 gen double `p5' = 0 replace `p1' = normal(`m1'-`b') replace `p2' = normal(`m2'-`b') - normal(`m1'-`b') replace `p3' = normal(`m3'-`b') - normal(`m2'-`b') replace `p4' = normal(`m4'-`b') - normal(`m3'-`b') replace `p5' = 1 - normal(`m4'-`b') replace `lnf' = (vig_`v'_==1)*ln(`p1')+(vig_`v'_==2)*ln(`p2')+(vig_`v'_==3)*ln(`p3')+(vig_`v'_==4)*ln(`p4')+(vig_`v'_==5)*ln(`p5') } end local varlist = "mobility vigact depressed worry pain discomfort relationships conflicts visionm visionf sleepn sleepm memory learning care appear" foreach v of local varlist { reshape long vig_`v'_, i(id) j(vignum) tabulate vignum, generate(vigdum) drop vigdum1 ml model lf gop (xb: vigdum*, nocons) (mu1: $cvars) (mu2: $cvars) (mu3: $cvars) (mu4: $cvars) if vig_`v'_!=. ml search ml maximize drop vigdum* reshape wide vig_`v'_, i(id) j(vignum) }
Code:
reshape long vig_`v'_, i(id) j(vignum) tabulate vignum, generate(vigdum)
I can't handle it myself. Any help would be very highly appreciated.
0 Response to Generalized ordered probit: "Looping over program" problem
Post a Comment