?*********************************************************************** ?*********************************************************************** ?*********************************************************************** ?*********************************************************************** ?======================================================================= ? Setup - Uses healthcare.lpj ?======================================================================= ?*********************************************************************** ?*********************************************************************** ?*********************************************************************** ?*********************************************************************** SETPANEL ; group = id ; pds = ti $ ti = the group size CREATE ; t = ndx(id,1) $ t = the within group index, 1,2,...,Ti CREATE ; yr=map(year) $ ?======================================================================= ? Section I. Ordered Choice ?======================================================================= ?----------------------------------------------------------------------- ? Part 1. Set up data for ordered choice modeling ?----------------------------------------------------------------------- Recode ; HSAT -> HS ; 0/4=0;5/6=1;7/8=2;9/9.1=3;9.5/10=4$ Histogram ; Rhs = HSAT,HS ; All ; Title=Health Satisfaction (0-10) collapsed to (0-4) $ ?----------------------------------------------------------------------- ? Part 2. Ordered probit vs. ordered logit ?----------------------------------------------------------------------- Namelist ; Demogrfc = age,income,female,married,hhkids $ OProbit ; If[year = 1988] ; Lhs = HS ; Rhs = one,demogrfc ; Table = ocprobit $ Partials ; If[year = 1988] ; Effects : demogrfc ; Summary ; Means ; Table=ME_Probt $ OLogit ; if[year = 1988] ; Lhs = HS ; Rhs = one,demogrfc ; table = oclogit $ Partials ; If[year = 1988] ; Effects : demogrfc ; Summary ; Means ; Table=ME_Logit $ Maketable ; ocprobit, oclogit $ Maketable ; ME_Probt,ME_Logit $ ?----------------------------------------------------------------------- ? Part 3. The Brant specification test ?----------------------------------------------------------------------- OLogit ; if[year = 1988] ; Lhs = HS ; Rhs = one,income,hhkids,age ; Brant$ ?----------------------------------------------------------------------- ? Part 4. Simulate an ordered logit model ?----------------------------------------------------------------------- OLogit ; if[year = 1988] ; Lhs = HS ; Rhs = one,demogrfc ; Margin ; full$ Simulate ; if[year = 1988] ; outcome=*;scenario:&income=.1(.1)2 | hhkids=0,1 ; means$ ?----------------------------------------------------------------------- ? Part 5. Partial effects in an ordered probit model ?----------------------------------------------------------------------- Oprobit ; if[year = 1988] ; Lhs = hs ; Rhs = one,income,income*income,educ,age*educ $ Partials ; if[year = 1988] ; outcome=* ; effects: income & age=25(3)65 ; Means $ Simulate ; if[year = 1988] ; Scenario: & age=25(3)65 ; Outcome=4 ; Plot(ci) ; Means $ Simulate ; if[year = 1988] ; Scenario: & age=25(3)65 ; Outcome=* ; Plot ; Means $ ?----------------------------------------------------------------------- ? 6. Different margins for an ordered choice model ?----------------------------------------------------------------------- OLogit ; If [year = 1988] ; Lhs = HS ; Rhs = one,demogrfc ; Margin ; full$ ?----------------------------------------------------------------------- ? 7. Generalized model with variable thresholds ?----------------------------------------------------------------------- ORDERED ; if[year = 1988] ; Lhs = hs ; Rhs = one,age,educ,female,income ;partials $ CREATE ; insuranc = public + addon $ ORDERED ; if[year = 1988] ; Lhs = hs ; Rhs = one,age,educ,female,income ; HO1 = hhkids,insuranc ; Partial Effects $ ?----------------------------------------------------------------------- ? 8. Sample Selection Model ?----------------------------------------------------------------------- Probit ; if[ti=7] ;Lhs = Public ; Rhs = One,Income,Hhkids ; Hold $ OProbit ; if[ti=7] ;Lhs = HS ; Rhs = one,age,educ,income,married ; Selection ; Maxit=20$ ?----------------------------------------------------------------------- ? 9. Panel Data Models ?----------------------------------------------------------------------- Ordered ; if[ti=7] ; Lhs = HS ; Rhs = one,income,hhkids,age ; table=pooled$ Ordered ; if[ti=7] ; Lhs = HS ; Rhs = one,income,hhkids,age ; panel ; FEM ;table=fem $ Ordered ; if[ti=7] ; Lhs = HS ; Rhs = one,income,hhkids,age ; panel ; Random ; Hpt=8 ; Maxit=25 ; table=rem $ Oprobit ; if[ti=7] ; lhs = HS ; Rhs = one,income,hhkids,age,female,married ; panel ; RPM ; Fcn = one(n),female(n),income(n) ; Pts=20 ; Halton ; Maxit=10 ; Table = RPM$ Maketable ; pooled,fem,rem $ Maketable ; rem,rpm $ ?======================================================================= ?======================================================================= ?======================================================================= ? Models for Count Data ?======================================================================= ?======================================================================= ?======================================================================= ?----------------------------------------------------------------------- ? 1. The effect of censoring ?----------------------------------------------------------------------- Histogram ; Rhs = DocVis $ Namelist ; X=One,Age,Educ,Income,hhkids,Married $ Poisson ; Lhs = DocVis ; Rhs = X ; Table = Full$ Create ; DocVis10 = Min(Docvis,10) $ Poisson ; Lhs = DocVis10 ; Rhs = X ; Table = Censored $ MakeTable ; Full,Censored $ ?----------------------------------------------------------------------- ? 2. Sample selection ?----------------------------------------------------------------------- Probit ; if[Ti=7] ; Lhs = Public ; Rhs = One,Income,Hhkids ; Hold $ Poisson ; if[Ti=7] ; Lhs = HospVis ; Rhs = X ; Selection ; MLE ; Hpt=8 $ ?----------------------------------------------------------------------- ? 3. Poisson and NB Models ?----------------------------------------------------------------------- Poisson ; if[Ti=7] ; Lhs = DocVis ; Rhs = X ; Table = Poisson$ Negbin ; if[Ti=7] ; Lhs = DocVis ; Rhs = X ; Table = NB2$ Negbin ; if[Ti=7] ; Lhs = DocVis ; Rhs = X ; Model = NB1 ; Table=NB1$ Negbin ; if[Ti=7] ; Lhs = DocVis ; Rhs = X ; Model = NBP ; Table=NBP$ MakeTable ; Poisson,NB2,NBP $ MakeTable ; NB* $ Poisson ; if[Ti=7] ; Lhs = DocVis ; Rhs = X ; Robust ; Table = Robust$ MakeTable ; Poisson,Robust ; StandardErrors$ ?----------------------------------------------------------------------- ? 4. Two Part Models ?----------------------------------------------------------------------- Histogram ; if[Ti=7] ; Rhs=DocVis $ Poisson ; if[Ti=7] ; Lhs = DocVis ; Rhs = X ; Hurdle ; Table=Hurdle$ Partials ; Effects : income / married $ Poisson ; if[Ti=7] ; Lhs = DocVis ; Rhs = X ; Rh2 = X ; Zip ; Table=zip$ Partials ; Effects : income / married $ MakeTable ; hurdle,zip $ ?----------------------------------------------------------------------- ? 5. Latent Class Models ?----------------------------------------------------------------------- Logit ; if[Ti=7] ;Lhs=doctor ; Rhs=one,age,educ,income,hhkids,married ; LCM ; pts=3 ; panel ; maxit=25 $ Poisson ; if[Ti=7] ;Lhs=docvis ; Rhs=one,age,educ,income,hhkids,married ; LCM ; pts=3 ; panel ; maxit=25 ; mar ; par$ Poisson ; if[Ti=7] ; Lhs = docvis ; Rhs=one,age,educ,income,hhkids,married ; LCM ; pts=5 ; panel ; maxit=25 ; mar ;par$ Poisson ; if[Ti=7] ; Lhs = docvis ; Rhs=one,age,educ,income,hhkids,married ; LCM = female ; pts=3 ; panel ; maxit=25 ; mar;par$ ?----------------------------------------------------------------------- ? Do the classes appear different? ?----------------------------------------------------------------------- Poisson ; if[Ti=7] ; Lhs = docvis ; Rhs=one,age,educ,income,hhkids,married ; LCM=female,working ; Panel ; Pts = 2 ; Parameters $ Reject ; Ti < 7 $ Create ; group7 = trn(7,0)$ Create ; pclass1 = classp_i(group7,1)$ Create ; class = 1*(pclass1 > .5) + 2*(pclass1 <= .5) $ Dstat ; if[Ti = 7] ;Rhs = Docvis ; Str = class $ Sample ; All$ ?----------------------------------------------------------------------- ? 6. Fixed Effects Models ?----------------------------------------------------------------------- Poisson ; if[Ti=7] ; FEM ; Panel ; Lhs=docvis ; Rhs=one,age,educ,income,hhkids,married$ Poisson ; if[Ti=7] ; Lhs=docvis ; Rhs=one,age,educ,income,hhkids,married $ Poisson ; if[Ti=7] ; Fixed effects ; Panel ; Lhs=docvis ; Rhs=one,age,educ,income,hhkids,married$ ?----------------------------------------------------------------------- ? Fixed effects with no time invariant variables ?----------------------------------------------------------------------- Negbin ; if[Ti=7] ; Lhs=docvis ; Rhs=one,age,educ,income,hhkids,married $ Negbin ; if[Ti=7] ; FEM ; Panel ; Lhs=docvis ; Table=TrueFE ; Rhs=one,age,educ,income,hhkids,married$ Negbin ; if[Ti=7] ; Lhs=docvis ; Rhs=one,age,educ,income,hhkids,married $ Negbin ; if[Ti=7] ; Fixed Effects ; Panel ; Lhs=docvis ; Rhs=one,age,educ,income,hhkids,married ; Table=HHGFE$ MakeTable ; TrueFE,HHGFE $ ?----------------------------------------------------------------------- ? Fixed effects with a time invariant variable, FEMALE ?----------------------------------------------------------------------- Negbin ; if[Ti=7] ; Lhs=docvis ; Rhs=one,age,educ,income,hhkids,married,female$ Negbin ; if[Ti=7] ; Fixed Effects ; Panel ; Lhs=docvis ; Rhs=one,age,educ,income,hhkids,married,female$ Negbin ; if[Ti=7] ; Lhs=docvis ; Rhs=one,age,educ,income,hhkids,married,female$ Negbin ; if[Ti=7] ; FEM ; Panel ; Lhs=docvis ; Rhs=one,age,educ,income,hhkids,married,female$ ?----------------------------------------------------------------------- ? 7. Random Parameters Count Data Model ?----------------------------------------------------------------------- Poisson ; if[Ti=7] ; Lhs=docvis ; Rhs=one,age,educ,income,hhkids,married,female,hs $ Poisson ; if[Ti=7] ; Lhs=docvis ; Rhs=one,age,educ,income,hhkids,married,female,hs ; RPM ; Halton ; Pts = 20 ; Panel ; maxit=10 ; Fcn = one(n),income(n),female(n),hs(n) ; Parameters $ Kernel ; Rhs = beta_i[3,Beta_FEM] ; Title=Distribution of E[beta_fem] Across Sample ; Grid ; Plot:Pen(Beta_FEM) = (red,2,solid) $