Announcement

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

  • Difference in two medians and 95% CI

    I saw a post using bootstrap to calculate the 95% CI for the difference of two medians and tried to run the command in the Do-File_Editor with the following information:
    /* Define a program to return medians */
    program define qq, rclass
    centile TimeSedation if StudyArm==1
    scalar m1 = r(c_1)
    centile TimeSedation if StudyArm==2
    scalar m2 = r(c_1)
    centile TimeSedation if StudyArm==3
    scalar m3 = r(c_1)
    #delim;
    bootstrap
    m1 = r(m1)
    m2 = r(m2)
    m3 = r(m3)
    d12 = (r(m1)-r(m2))
    d32 = (r(m3)-r(m2))
    DID = (r(m3)-2*r(m2)+r(m1)),
    ties strata(StudyArm) rep(1000) nodots saving(bs01, replace): qq;
    #delim cr
    estat bootstrap

    It works the first time but when I tried to re-run it again, it returned with the following message:

    . /* Define a program to return medians */
    . program define qq, rclass
    1. centile TimeSedation if StudyArm==1
    2. scalar m1 = r(c_1)
    3. centile TimeSedation if StudyArm==2
    4. scalar m2 = r(c_1)
    5. centile TimeSedation if StudyArm==3
    6. scalar m3 = r(c_1)
    7. #delim;
    delimiter now ;
    . bootstrap
    > m1 = r(m1)
    > m2 = r(m2)
    > m3 = r(m3)
    > d12 = (r(m1)-r(m2))
    > d32 = (r(m3)-r(m2))
    > DID = (r(m3)-2*r(m2)+r(m1)),
    > ties strata(StudyArm) rep(1000) nodots saving(bs01, replace): qq;
    8. #delim cr
    delimiter now cr
    . estat bootstrap
    9.
    unexpected end of file
    r(612);

    end of do-file

    r(612);

    Any ideas how to fix it? Or any advice on getting the 95% CI?

    Thanks!

  • #2
    You never say when the program ends. You need an

    Code:
    end
    statement. See the help for program.

    I guess this is closer to what you want.


    Code:
    program define qq, rclass
        centile TimeSedation if StudyArm==1
        return scalar m1 = r(c_1)
        centile TimeSedation if StudyArm==2
        return scalar m2 = r(c_1)
        centile TimeSedation if StudyArm==3
        return scalar m3 = r(c_1)
    end
    
    bootstrap m1 = r(m1) m2 = r(m2)  m3 = r(m3) ///
    d12 = (r(m1)-r(m2)) d32 = (r(m3)-r(m2)) DID = (r(m3)-2*r(m2)+r(m1)), ///
    ties strata(StudyArm) rep(1000) nodots saving(bs01, replace): qq;
    
    estat bootstrap
    Last edited by Nick Cox; 11 Jul 2016, 04:44.

    Comment


    • #3
      Thanks Nick for your reply but it returned with different error messages as I tried to use the code you suggested. Did I miss anything this time? I pasted the code on the Do-file editor.


      . program define qq, rclass
      1. centile TimeSedation if StudyArm==1
      2. return scalar m1 = r(c_1)
      3. centile TimeSedation if StudyArm==2
      4. return scalar m2 = r(c_1)
      5. centile TimeSedation if StudyArm==3
      6. return scalar m3 = r(c_1)
      7. end

      .
      . bootstrap m1 = r(m1) m2 = r(m2) m3 = r(m3) ///
      > d12 = (r(m1)-r(m2)) d32 = (r(m3)-r(m2)) DID = (r(m3)-2*r(m2)+r(m1)), ///
      > ties strata(StudyArm) rep(1000) nodots saving(bs01, replace): qq;
      qq; command not found
      r(111);

      end of do-file

      r(111);



      . program define qq, rclass

      . do "C:\Users\celeney\AppData\Local\Temp\STD01000000.t mp"

      . centile TimeSedation if StudyArm==1

      -- Binom. Interp. --
      Variable | Obs Percentile Centile [95% Conf. Interval]
      -------------+-------------------------------------------------------------
      TimeSedation | 111 50 11 8.656538 15

      . return scalar m1 = r(c_1)
      non r-class program may not set r()
      r(151);

      end of do-file

      r(151);

      Comment

      Working...
      X