Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Combine results from linear and logistic regression into the same table?

    How can I combine results from a linear regression and a logistic regression into the same table?

    Using the code below gives me first the correct table of the linear regression, and then when running the second part it is incorporated into the second table. Can I combine them into the same table with only the results from the logistic regression having %?

    *start with a new collection
    collect clear

    foreach y in D_vit_total dvit_dietary D_vit_1000kcal {
    quietly regress `y' AGE i.METHOD i.SEASON i.CO2_quintiles_sex if(SEX==0)
    * collect the marginal predicted probabilities as percents
    collect _r_b, tags(var[`y']) : ///
    margins i.CO2_quintiles_sex
    regress `y' CO2_quintiles_sex AGE DATUM i.SEASON if(SEX==0)
    * collect beta and p-trend
    collect get ///
    beta=(_r_b[CO2_quintiles_sex]) ///
    ptrend=(_r_p[CO2_quintiles_sex]) ///
    , tags(var[`y'])
    }

    collect style column, dups(center)
    * formats
    collect style cell result[_r_b], nformat(%4.1f)
    collect style cell result[beta], nformat(%9.2f)
    collect style cell result[ptrend], nformat(%5.3f)
    * labels
    collect label levels result beta "β" ptrend "p-trend", modify
    * select results to show/hide in the header
    collect style header result[_r_b], level(hide)
    * layout
    collect layout (var) (colname#result[_r_b] result[beta ptrend])



    *Logistic.
    foreach y in D_vit_belowAR_diet D_vit_belowRI_diet {
    quietly logit `y' AGE DATUM i.SEASON i.CO2_quintiles_sex if(SEX==0)
    * collect the marginal predicted probabilities as percents
    collect _r_b, tags(var[`y']) : ///
    margins i.CO2_quintiles_sex, expression(100*predict(pr))
    logit `y' CO2_quintiles_sex AGE DATUM i.SEASON if(SEX==0)
    * collect beta and p-trend
    collect get ///
    beta=(_r_b[CO2_quintiles_sex]) ///
    ptrend=(_r_p[CO2_quintiles_sex]) ///
    , tags(var[`y'])
    }

    collect style column, dups(center)
    * formats
    collect style cell result[_r_b], nformat(%4.1f) sformat("%s%%")
    collect style cell result[beta], nformat(%9.2f)
    collect style cell result[ptrend], nformat(%5.3f)
    * labels
    collect label levels result beta "β" ptrend "p-trend", modify
    * select results to show/hide in the header
    collect style header result[_r_b], level(hide)
    * layout
    collect layout (var) (colname#result[_r_b] result[beta ptrend])

    Click image for larger version

Name:	Skärmklipp5.JPG
Views:	1
Size:	39.7 KB
ID:	1741495

    Click image for larger version

Name:	Skärmklipp6.JPG
Views:	1
Size:	57.7 KB
ID:	1741496

    Thank you!!

  • #2
    Is there also a way to add the confidence intervals or the standard deviation to each estimate? Example below:

    Click image for larger version

Name:	Skärmklipp7.JPG
Views:	1
Size:	101.3 KB
ID:	1741498

    Comment

    Working...
    X