Announcement

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

  • Put in excel - automate the process

    Hello,

    I am running a multilevel analysis and I am adjusting for confounders. I want to export my results on excel.
    However, I only want to export the beta coefficients and 95%CI of my main predictor and not of the other covariates.

    I am using putexcel command and matrix list r(table) but I am entering manually the column number from the matrix. Is there a way to automate the process.

    This is the codes I am using:

    "putexcel set "Multiple regression.xlsx", sheet(Subtype) modify
    melogit Outcome age i.gender i.Predictor [pw= ponderation] || sclid: , pweight(weight_school)
    ereturn list
    matrix list r(table)
    local beta=string(r(table)[1,5], "%9.4f")
    local ll=string(r(table)[5,5], "%9.4f")
    local ul=string(r(table)[6,5], "%9.4f")
    local all=`" `b' [ `ll' - `ul' ] "'
    putexcel B4 =`"`all'"'
    "
    Instead of manually write the column number from the matrix table (i.e., 5), is there a code to automate the process?

    Thank you !

  • #2
    You don't say which of the variables in the regression is your "main" predictor. To illustrate the approach, I will assume that it's Predictor, and that this one is a dichotomous 0/1 variable.
    Code:
    local beta=string(r(table)[1,"Outcome:1.Predictor"], "%9.4f")
    local ll=string(r(table)[5,"Outcome:1.Predictor"], "%9.4f")
    local ul=string(r(table)[6,"Outcome:1.Predictor"], "%9.4f")
    I do not remember exactly when Stata introduced the ability to use term names as indices in referring to a matrix, but all the recent versions of Stata support this. If yours doesn't, then you can instead calculate the numeric index using the -colnumb()- function. See -help colnumb-.

    Comment


    • #3
      It worked!
      Thank you so much Clyde !

      Comment

      Working...
      X