Announcement

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

  • "logistic" in foreach loop


    I am very new with Stata
    I preform simple logistic regression and want to extract odds ratios and confidence intervals from r(table).
    If I put each comment one by one in the prompt, the result is fine.
    But several problems pop up when I try to write the same thing into the foreach loop in a do file. Please help me
    I have tried to search online, but find nothing.
    ------------------------------------------------------------------------------------------------------------------------------

    local x age50 sex bmi224
    local y ckd60

    local i=1
    mat all=J(35,5,.)

    foreach v of local x {

    logistic `y' `v' if nonBnonC==1 /// (`y' is not put in the model)

    matrix A =`r(table)' /// A is not found.

    mat all[`i',1]= round(A[`i',1],0.001)
    mat all[`i',2]=round(A[`i',5],0.001)
    mat all[`i',3]=round(A[`i',6],0.001)
    mat all[`i',4]=round( normal(-abs(A[`i',3]))*2,0.001)

    local i=`i'+1
    }
    matrix rowname A=`x'
    matrix colname A= "Odds Ratio" "Lower Limit" "Upper Limit" p
    Last edited by Cheng YuanLung; 08 May 2018, 23:05.

  • #2
    Are you running the code all at once not in chunks from a do-file editor window?

    Comment


    • #3
      Thank you for your response, Nick.

      local x age50 sex bmi224 /// wc90 sbp130 dbp85 glu100 chol200 ldl130 hdl40 tg150 alt40 ast40 ggt61 alb4 plt150k fatty_liver
      local y ckd60

      I put "///" behind the independent variables, which was wrong and confused STATA. I change "///" to "//," and the problems just go away.

      Comment

      Working...
      X