Announcement

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

  • How to obtain confidence interval & p-value from stmh command result table

    Good Morning,

    I am a relatively new STATA15 user. I need some help obtaining the confidence interval and p-value output after executing the stmh command. e.g:

    Code:
    stmh age_at_start, c(2,1)
    
    
             failure _d:  ltfup_status
       analysis time _t:  date_of_nextapp/365.25
      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
            ----------------------------------------------------------
    I am only able to get the RR value using the return list command. Your help will be greatly appreciated.

    Thanks,

    Paul

  • #2
    the p-value and the CI are saved in the returned results (as shown in the help file) so your question is unclear; you can, for example, -display- them:
    Code:
    di "p-value is " r(p)
    etc.

    but we can't give exact code unless we know what you want to do with these

    Comment


    • #3
      Hi Rich,

      I have tried display r(p), display display r(lb) and display r(ub), still not getting any results. I want to populate these values into an excel file using putexcel. Kindly help.

      Thanks,

      Paul
      Last edited by Paul Somwe; 05 Jul 2020, 04:12.

      Comment


      • #4
        as you are still not following the FAQ advice (show exact commands and sets of commands), I can only guess that you are doing something that "destroys" the returned values prior to your attempts; please read the FAQ and show us exactly what you are telling Stata to do and exactly how Stata is responding

        Comment


        • #5
          Hi Rich, the exact commands I executed and associated results are:

          Code:
          . stmh viral_load_status, c(1,0)
          
                   failure _d:  ltfup_status
             analysis time _t:  date_of_nextapp/365.25
            enter on or after:  time art_start_date
                           id:  artnumber
          
          Maximum likelihood estimate of the rate ratio
            comparing viral_load_status==1 vs. viral_load_status==0
          
          RR estimate, and lower and upper 95% confidence limits
          
                  ----------------------------------------------------------
                       RR       chi2        P>chi2      [95% Conf. Interval]
                  ----------------------------------------------------------
                    3.550     419.71        0.0000         3.119      4.041
                  ----------------------------------------------------------
          
          . return list
          
          scalars:
                           r(RR) =  3.550137764026656
          The return list command is only giving me the RR value. The p-value and confidence interval values are not given. These are the values I want so that I may popuate them into an excel file using putexcel.

          Thanks,

          Paul

          Comment


          • #6
            What do you get when you type
            Code:
            which stmh.ado
            at the command line?

            I don't know what Stata Release 15 had, but this is what I get with the next release.

            *! version 6.1.1 09apr2020

            Do you get something more like the following?

            . type "http://www.stata.com/stb/stb41/ssa10_1/stmh.ado"
            *! version 2.0 dgc/mh Sep 1997 STB-41 ssa10.1
            *! this an st wrapper for dymh

            Comment


            • #7
              Hi Joseph,

              See below:

              Code:
              . which stmh.ado
              C:\Program Files (x86)\ado\base\s\stmh.ado
              *! version 6.1.0  16apr2007
              is there something you are trying to ascertain?

              Thanks,

              paul

              Comment


              • #8
                The return list command is only giving me the RR value. The p-value and confidence interval values are not given.
                I do not think that this is a version issue. One workaround is to log the session when executing the command. Then you can read these numbers using infile. My example shows that these will be in line 14 and as the table is standard, I do not think that this will be variable.

                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
                keep in 14
                local chi2=  word(v1, 2)
                local p= word(v1, 3)
                local ci= "[`=word(v1, 4)' `=word(v1, 5)']"
                restore
                Res.:

                Code:
                . 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'"
                4.84
                
                . di "`p'"
                0.0277
                
                . di "`ci'"
                [0.288 0.941]

                Comment


                • #9
                  Andrew Musau regardless of whether #8 is correct about the version not being the problem the OP should update their version of Stata (it is free to do)

                  Comment


                  • #10
                    Absolutely.

                    Comment


                    • #11
                      Thank you all, will try your suggestions!

                      Comment


                      • #12
                        Originally posted by Andrew Musau View Post

                        I do not think that this is a version issue. One workaround is to log the session when executing the command. Then you can read these numbers using infile. My example shows that these will be in line 14 and as the table is standard, I do not think that this will be variable.

                        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
                        keep in 14
                        local chi2= word(v1, 2)
                        local p= word(v1, 3)
                        local ci= "[`=word(v1, 4)' `=word(v1, 5)']"
                        restore
                        Res.:

                        Code:
                        . 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'"
                        4.84
                        
                        . di "`p'"
                        0.0277
                        
                        . di "`ci'"
                        [0.288 0.941]
                        Hi Andrew,

                        I have tried your example and still the chi2, p, and ci interval values are not being displayed. I am honestly stuck now because am not quite sure what could be the issue.

                        Thanks,

                        Paul

                        Comment


                        • #13
                          Can you show your exact commands and the resulting Stata output? Place these within CODE delimiters.

                          Comment


                          • #14
                            Originally posted by Andrew Musau View Post
                            Can you show your exact commands and the resulting Stata output? Place these within CODE delimiters.
                            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
                            Last edited by Paul Somwe; 07 Jul 2020, 05:07.

                            Comment


                            • #15
                              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'"

                              Comment

                              Working...
                              X