Announcement

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

  • collect different types of results

    Hello Statalisters, I'm trying to collect results from a logistic regression, but also classification statistics and an AUC for some 20 variables and want to place them all in a table.

    I have code that I developed that sort of works but I know it's not quite right and I am unsuccessful placing it all in a loop to pass over every variable. I have some categorical and continuous variables too.

    code is below:
    Code:
    collect clear
    collect or=_r_b lower=_r_lb upper=_r_ub,:logistic concussed c.severity if _mi_m==0
    lsens, genprob(cutoff) gensens(sens) genspec(spec) replace
    generate float youden = (sens + spec) - 1
    egen float max_youden = max(youden)
    sum cutoff if youden == max_youden
    scalar cutoffs = r(mean)
    collect sens = r(P_1n) spec=r(P_0p) correct=r(P_corr),:estat classification,cutoff(`=cutoffs')
    collect auc = r(area):lroc
    collect dims
    collect levelsof result
    collect label list result, all
    collect levelsof labels
    collect levelsof cmdset
    collect levelsof colname
    collect levelsof result_type
    collect style cell result, nformat(%7.4f)
    collect style showbase off
    collect style column, extraspace(1)
    collect style header result, level(label)
    collect layout () (colname[severity]#result[or lower upper] result[sens spec correct auc])
    collect preview
    drop spec sens cutoff youden max_youden
    
    
    . collect preview
    
    --------------------------------------------------------------------
    severity   severity   severity     sens      spec   correct      auc
          or      lower      upper                                      
    --------------------------------------------------------------------
      1.0812     1.0738     1.0886   3.9335   77.1323   79.2265   0.7841
    --------------------------------------------------------------------
    Is there a way to place all that in a loop to make 1 big table of these specific results?

    Thank you kindly.

  • #2
    I think the basic process would be something like this:

    Code:
    collect clear
    
    local vars_to_collect var1 var2 var3 var4 var5
    foreach var of varlist `vars_to_collect' {
         collect create `var'
         ... your commands to collect various results...
         collect addtags Variable[`var']
    }
    
    collect combine comb = `vars_to_collect'
    collect layout (Variable) (colname[severity]#result[or lower upper] result[sens spec correct auc])
    ... commands to format your table...
    collect preview

    Comment

    Working...
    X