stata - Plotting log odds against mid-point of category -


i have binary outcome variable (disease) , continuous independent variable (age). there's cluster variable clustvar. logistic regression assumes log odds linear respect continuous variable. visualize this, can categorize age (for example, 0 <5, 5 <15, 15 <30, 30 <50 , 50+) , plot log odds against category number using:

logistic disease i.agecat, vce(cluster clustvar) margins agecat, predict(xb) marginsplot 

however, since categories not equal width, better plot log odds against mid-point of categories. there way can manually define values plotted on x-axis marginsplot should 2.5, 10, 22.5, 40 , (slightly arbitrarily) 60, , have points spaced appropriately?

if interested, achieved required graph follows:

  1. recategorised age variable differently using (integer) labels represent mid-point of category:

    gen agecat = .  replace agecat = 3 if age<6  replace agecat = 11 if age>=6 & age<16  replace agecat = 23 if age>=16 & age<30  replace agecat = 40 if age>=30 & age<50  replace agecat = 60 if age>=50 & age<. 
  2. for labelling purposes, created label:

    label define agecat 3 "less 5y" 11 "10 15y" 23 "15 <30y" 40 "30 <50y" 60 "over 50 years"  label values agecat 
  3. ran logistic regression above:

    logistic disease i.agecat, vce(cluster clustvar) 
  4. used margins , plot using marginsplot:

    margins agecat, predict(xb)  marginsplot  

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -