Skip to Main Content

  Reading and Analyzing the Hospital Doctor Patient Dataset | Stata Code Fragments

You can read the Hospital Doctor Patient Dataset into Stata and run many linear and
generalized linear mixed effects models into Stata using this code. The output
is not included, but the syntax is. For more details on the dataset,
you should see the original R page that simulates the data
HDP Simulation.


*Grab the most recent version from the internet
insheet using "https://stats.idre.ucla.edu/stat/data/hdp.csv", comma

foreach i of varlist familyhx smokinghx sex cancerstage school {
  encode `i', gen(`i'2)
  drop `i'
  rename `i'2 `i'
}

xtmixed tumorsize i.familyhx lengthofstay i.cancerstage i.smokinghx##c.age || did: lengthofstay

xtmixed co2 i.familyhx lengthofstay i.cancerstage i.smokinghx##c.age || did: lengthofstay

xtmixed pain i.sex c.il6##c.crp || did:

xtmixed wound rbc i.married##i.sex experience || hid: || did: rbc

xtmixed mobility age bmi experience i.school lawsuits medicaid || hid: || did:

xtmepoisson ntumors age c.bmi##i.familyhx lengthofstay il6 crp i.cancerstage c.experience##i.cancerstage || hid: || did:

xtmepoisson nmorphine age i.sex lengthofstay bmi i.cancerstage || did: bmi

xtmelogit remission age lengthofstay i.familyhx il6 crp i.cancerstage experience || hid: || did: lengthofstay

*not technically correct, should be a logit link with a beta distribution
xtmelogit lungcapacity rbc c.il6#c.crp i.smokinghx##i.familyhx experience i.school || did: