Announcement

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

  • #16
    Originally posted by Andrew Musau View Post
    Thanks for the example. What is biting is the observation number. It's better to automate the search rather than relying on a manual approach.

    Code:
    webuse diet, clear
    qui stset dox, origin(time dob) enter(time doe) id(id) scale(365.25) fail(fail==1 3 13)
    preserve
    qui log using firstfile, name(log1) text replace
    stmh hienergy
    log close log1
    insheet using "firstfile.log", clear
    gen obs=_n
    qui sum obs if regexm(v1, "P>chi2")
    keep in `=r(min)+2'
    local chi2= word(v1, 2)
    local p= word(v1, 3)
    local ci= "[`=word(v1, 4)' `=word(v1, 5)']"
    restore
    di "`chi2'"
    di "`p'"
    di "`ci'"
    Hi Andrew Musau

    Your code has worked but when I try to replacing some of your code with mine in the hope of achieving the same results I get an error. See code below:

    Code:
    . qui stset date_of_nextapp, fail(ltfup_status) id(artnumber) origin(art_start_date) enter(art_start_date)  scale(365.25) 
    
    . preserve
    
    . qui log using firstfile, name(log1) text replace
    
    . stmh age_at_artstart2, c(2,1)
    
             failure _d:  ltfup_status
       analysis time _t:  (date_of_nextapp-origin)/365.25
                 origin:  time art_start_date
      enter on or after:  time art_start_date
                     id:  artnumber
    
    Maximum likelihood estimate of the rate ratio
      comparing age_at_artstart2==2 vs. age_at_artstart2==1
    
    RR estimate, and lower and upper 95% confidence limits
    
            ----------------------------------------------------------
                 RR       chi2        P>chi2      [95% Conf. Interval]
            ----------------------------------------------------------
              2.041     143.33        0.0000         1.812      2.300
            ----------------------------------------------------------
    
    . log close log1
          name:  log1
           log:  C:\Users\Paul.Somwe\Documents\Tx abstract\firstfile.log
      log type:  text
     closed on:   7 Jul 2020, 14:20:38
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    . insheet using  "firstfile.log", clear
    (3 vars, 19 obs)
    
    . gen obs=_n
    
    . qui sum obs if regexm(v1, "P>chi2")
    v1 not found
    r(111);
    Thank you once again,

    Paul

    Comment


    • #17
      Show the output of the following:

      Code:
      insheet using "firstfile.log", clear
      list

      Comment


      • #18
        Originally posted by Paul Somwe View Post

        Hi Andrew Musau ,

        I ran the exact code you shared i.e.

        Code:
        . webuse diet, clear
        (Diet data with dates)
        
        . qui stset dox, origin(time dob) enter(time doe) id(id) scale(365.25) fail(fail==1 3 13)
        
        . preserve
        
        . qui log using firstfile, name(log1) text replace
        
        . stmh hienergy
        
        failure _d: fail == 1 3 13
        analysis time _t: (dox-origin)/365.25
        origin: time dob
        enter on or after: time doe
        id: id
        
        Maximum likelihood estimate of the rate ratio
        comparing hienergy==1 vs. hienergy==0
        
        RR estimate, and lower and upper 95% confidence limits
        
        ----------------------------------------------------------
        RR chi2 P>chi2 [95% Conf. Interval]
        ----------------------------------------------------------
        0.520 4.84 0.0277 0.288 0.941
        ----------------------------------------------------------
        
        . log close log1
        name: log1
        log: C:\Users\Paul.Somwe\Documents\Tx abstract\firstfile.log
        log type: text
        closed on: 7 Jul 2020, 13:04:21
        --------------------------------------------------------------------------------------------------------------------------
        
        . insheet using "firstfile.log", clear
        (1 var, 20 obs)
        
        . keep in 14
        (19 observations deleted)
        
        . local chi2= word(v1, 2)
        
        . local p= word(v1, 3)
        
        . local ci= "[`=word(v1, 4)' `=word(v1, 5)']"
        
        . restore
        
        .
        . stmh hienergy
        
        failure _d: fail == 1 3 13
        analysis time _t: (dox-origin)/365.25
        origin: time dob
        enter on or after: time doe
        id: id
        
        Maximum likelihood estimate of the rate ratio
        comparing hienergy==1 vs. hienergy==0
        
        RR estimate, and lower and upper 95% confidence limits
        
        ----------------------------------------------------------
        RR chi2 P>chi2 [95% Conf. Interval]
        ----------------------------------------------------------
        0.520 4.84 0.0277 0.288 0.941
        ----------------------------------------------------------
        
        . di "`chi2'"
        
        
        . di "`p'"
        
        
        . di "`ci'"
        [ ]
        Notice that the chi2, p and ci values are not being displayed?

        Thanks,

        Paul
        Hi Andrew,

        Thanks once again for your help! I successfully ran the edited version of your example and it works just fine. However, when I tried to rerun the same code with minor edits made to stset command, I get an error (v1 not found). Kindly see code below:

        Code:
        . qui stset date_of_nextapp, fail(ltfup_status) id(artnumber) origin(art_start_date) enter(art_start_date)  scale(365.25) 
        
        . preserve
        
        . qui log using firstfile, name(log1) text replace
        
        . stmh age_at_artstart2, c(2,1)
        
                 failure _d:  ltfup_status
           analysis time _t:  (date_of_nextapp-origin)/365.25
                     origin:  time art_start_date
          enter on or after:  time art_start_date
                         id:  artnumber
        
        Maximum likelihood estimate of the rate ratio
          comparing age_at_artstart2==2 vs. age_at_artstart2==1
        
        RR estimate, and lower and upper 95% confidence limits
        
                ----------------------------------------------------------
                     RR       chi2        P>chi2      [95% Conf. Interval]
                ----------------------------------------------------------
                  2.041     143.33        0.0000         1.812      2.300
                ----------------------------------------------------------
        
        . log close log1
              name:  log1
               log:  C:\Users\Paul.Somwe\Documents\Tx abstract\firstfile.log
          log type:  text
         closed on:   7 Jul 2020, 14:20:38
        --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        
        . insheet using  "firstfile.log", clear
        (3 vars, 19 obs)
        
        . gen obs=_n
        
        . qui sum obs if regexm(v1, "P>chi2")
        v1 not found
        r(111);
        Thanks,

        Paul

        Comment


        • #19
          You have not responded to #13. Show me the output of the list command

          Code:
          qui stset date_of_nextapp, fail(ltfup_status) id(artnumber) origin(art_start_date) enter(art_start_date) scale(365.25)
          preserve
          qui log using firstfile, name(log1) text replace
          stmh age_at_artstart2, c(2,1)
          log close log1
          insheet using "firstfile.log", clear
          list

          Comment


          • #20
            Originally posted by Andrew Musau View Post
            You have not responded to #13. Show me the output of the list command

            Code:
            qui stset date_of_nextapp, fail(ltfup_status) id(artnumber) origin(art_start_date) enter(art_start_date) scale(365.25)
            preserve
            qui log using firstfile, name(log1) text replace
            stmh age_at_artstart2, c(2,1)
            log close log1
            insheet using "firstfile.log", clear
            list
            Hi Andrew,

            See output below:

            Code:
                        
            1.    stmhage_at_artstart2            
                failure _d:  ltfup_status            
                            
                c2    v3        
                    .        
                            
            
                            
            2.    stmhage_at_artstart2            
                analysis time _t:  (date_of_nextapp-origin)/365.25            
                            
                c2    v3        
                    .        
                            
            
                            
            3.    stmhage_at_artstart2            
                origin:  time art_start_date            
                            
                c2    v3        
                    .        
                            
            
                            
            4.    stmhage_at_artstart2            
                enter on or after:  time art_start_date            
                            
                c2    v3        
                    .        
                            
            
                            
            5.    stmhage_at_artstart2            
                id:  artnumber            
                            
                c2    v3        
                    .        
                            
            
                            
            6.    stmhage_at_artstart2            
                Maximum likelihood estimate of the rate ratio            
                            
                c2    v3        
                    .        
                            
            
                            
            7.    stmhage_at_artstart2            
                comparing age_at_artstart2==2 vs. age_at_artstart2==1            
                            
                c2    v3        
                    .        
                            
            
                            
            8.    stmhage_at_artstart2            
                RR estimate            
                            
                c2    v3        
                and lower and upper 95% confidence limits    .        
                            
            
                            
            9.    stmhage_at_artstart2            
                            
                            
                c2    v3        
                    .        
                            
            
                            
            10.    stmhage_at_artstart2            
                RR       chi2        P>chi2      [95% Conf. Interval]            
                            
                c2    v3        
                    .        
                            
            
                            
            11.    stmhage_at_artstart2            
                            
                            
                c2    v3        
                    .        
                            
            
                            
            12.    stmhage_at_artstart2            
                2.041     143.33        0.0000         1.812      2.300            
                            
                c2    v3        
                    .        
                            
            
                            
            13.    stmhage_at_artstart2            
                            
                            
                c2    v3        
                    .        
                            
            
                            
            14.    stmhage_at_artstart2            
                . log close log1            
                            
                c2    v3        
                    .        
                            
            
                            
            15.    stmhage_at_artstart2            
                name:  log1            
                            
                c2    v3        
                    .        
                            
            
                            
            16.    stmhage_at_artstart2            
                log:  C:\Users\Paul.Somwe\Documents\Tx abstract\firstfile.log            
                            
                c2    v3        
                    .        
                            
            
                            
            17.    stmhage_at_artstart2            
                log type:  text            
                            
                c2    v3        
                    .        
                            
            
                            
            18.    stmhage_at_artstart2            
                closed on:   7 Jul 2020            
                            
                c2    v3        
                15:32:51    .        
                            
            
                            
            19.    stmhage_at_artstart2            
                        -..    
                            
                c2    v3        
                    .

            Comment


            • #21
              Thanks. Try

              Code:
              insheet using "firstfile.log", clear
              gen obs=_n
              qui sum obs if regexm(stmhage_at_artstart2, "P>chi2")
              keep in `=r(min)+2'
              local chi2= word(stmhage_at_artstart2, 2)
              local p= word(stmhage_at_artstart2, 3)
              local ci= "[`=word(stmhage_at_artstart2, 4)' `=word(stmhage_at_artstart2, 5)']"
              restore
              di "`chi2'"
              di "`p'"
              di "`ci'"

              Comment


              • #22
                Hi Andrew,

                The above edited code has worked. Just for my own knowledge, does this mean that there is no other straightforward way to obtain these values? Why doesn't the
                Code:
                . return list
                
                scalars:
                                 r(RR) =  2.041365521809395
                command output the p and confidence interval values together with RR value. Otherwise, your help is very much appreciated!

                Thanks,

                Paul

                Comment


                • #23
                  Paul, more recent versions of the -stmh- command do return those values as scalars. This is the case in my copy of Stata 16.1.

                  Comment


                  • #24
                    Did you follow the earlier advice to update your Stata installation? It appears that this was fixed in a recent update.

                    Code:
                    update all

                    Comment


                    • #25
                      Originally posted by Leonardo Guizzetti View Post
                      Paul, more recent versions of the -stmh- command do return those values as scalars. This is the case in my copy of Stata 16.1.
                      Hi Leonardo Guizzetti

                      Guess I need to get myself a copy of STATA 16 then, thanks for your feedback!

                      Regards,

                      Paul

                      Comment


                      • #26
                        Originally posted by Andrew Musau View Post
                        Did you follow the earlier advice to update your Stata installation? It appears that this was fixed in a recent update.

                        Code:
                        update all
                        Hi Andrew Masau,

                        Yes I did, though I got an error when downloading the update files. I suspect my internet network connection signal is weak. I resorted to going to the STATA website to download the update. I will give you feedback on whether the update will work or not.

                        Thank you,

                        Paul

                        Comment


                        • #27
                          Hi Andrew Musau,

                          I have run into another frustrating situation again. I am not sure why it is so difficult to obtain stored results in STATA15/IC. I executed the following command:

                          Code:
                          strate facility_code, per(1000)
                          
                                   failure _d:  ltfup_status
                             analysis time _t:  (date_of_nextapp-origin)/365.25
                                       origin:  time art_start_date
                            enter on or after:  time art_start_date
                                           id:  artnumber
                          
                          Estimated rates (per 1000) and lower/upper bounds of 95% confidence intervals
                          (15288 records included in the analysis)
                          
                            +-----------------------------------------------------+
                            | facili~e      D        Y     Rate    Lower    Upper |
                            |-----------------------------------------------------|
                            |        1   2617   5.0111   522.24   502.61   542.64 |
                            |        2   1030   2.8195   365.31   343.67   388.31 |
                            |        3   2798   4.2639   656.21   632.34   680.98 |
                            |        4   2668   4.4831   595.12   572.96   618.13 |
                            +-----------------------------------------------------+
                          The
                          Code:
                           return list
                          command does not provide any output of the stored rate values. Imagine I have a over 200 facilities and I need the rate and ci for each, does this mean I will have to manually copy the values into excel?

                          Thanks,

                          Paul

                          Comment


                          • #28
                            It is unfortunate that Stata does not store these scalars. I can replicate the problem with the most updated version of Stata 16. You can use the procedure that I suggested earlier, try to understand what the code does. Below I highlight the lines that you need to change in your code, the rest should stay the same.

                            Code:
                            webuse diet, clear
                            stset dox, origin(time doe) id(id) scale(365.25) fail(fail==1 3 13)
                            stsplit ageband, at(40(10)70) after(time=dob) trim
                            preserve
                            qui log using firstfile, name(log1) text replace
                            strate ageband, per(1000)
                            log close log1
                            insheet using "firstfile.log", clear
                            gen obs=_n
                            levelsof obs if regexm(v1, "Lower     Upper"), local(first)
                            levelsof obs if regexm(v1, "Notes"), local(last)
                            keep if inrange(obs, `first', `=`last'-2')
                            drop in 2
                            replace v1= trim(itrim(v1))
                            split v1, p(" ")
                            keep v12-v17
                            export excel using myfile, replace
                            restore
                            Res.:

                            Code:
                             strate ageband, per(1000)
                            
                                     failure _d:  fail == 1 3 13
                               analysis time _t:  (dox-origin)/365.25
                                         origin:  time doe
                                             id:  id
                                           note:  ageband<=40 trimmed
                            
                            Estimated failure rates
                            Number of records  =       729
                            
                              +----------------------------------------------------+
                              | ageband    D        Y      Rate    Lower     Upper |
                              |----------------------------------------------------|
                              |      40    6   0.9070    6.6152   2.9719   14.7246 |
                              |      50   18   2.1070    8.5428   5.3823   13.5591 |
                              |      60   22   1.4933   14.7325   9.7007   22.3746 |
                              +----------------------------------------------------+
                               Notes: Rate = D/Y = failures/person-time (per 1000).
                                      Lower and Upper are bounds of 95% confidence intervals.
                            
                            
                            
                            . import excel myfile, first clear
                            (6 vars, 3 obs)
                            
                            . l
                            
                                 +----------------------------------------------------+
                                 | ageband    D        Y      Rate    Lower     Upper |
                                 |----------------------------------------------------|
                              1. |      40    6   0.9070    6.6152   2.9719   14.7246 |
                              2. |      50   18   2.1070    8.5428   5.3823   13.5591 |
                              3. |      60   22   1.4933   14.7325   9.7007   22.3746 |
                                 +----------------------------------------------------+

                            Comment


                            • #29
                              Thank you Andrew Musau, your help is greatly appreciated!

                              Comment

                              Working...
                              X