Announcement

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

  • looping and exporting multiple regression results into a single table

    Hello, I am attempting to export the results from multiple univariate regression models estimated using looping into a single table that includes the coefficient, se, p-value and CIs. I have tried below and run into the error: estimation result : not found

    I appreciate any help. Thanks.

    foreach var of varlist updrs3_total_on updrs3_total_off ///
    updrs1_cogimp_11 updrs1_lighthead_112 updrs1_fatigue_113 updrs2_freezing_213 {
    estout: quietly nbreg falls_total `var'
    }




    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(falls_total updrs3_total_on updrs3_total_off) byte(updrs1_cogimp_11 updrs1_lighthead_112 updrs1_fatigue_113 updrs2_freezing_213)
     0 29 38 0 0 0 0
     0 14 23 1 2 1 0
     0 30 38 0 1 1 0
     2 24 40 1 1 1 2
     4 32 39 0 2 1 1
     0 14 20 1 1 1 0
     0 32 37 1 0 0 0
     1 36 48 0 0 1 3
     0 24 39 3 1 2 0
     1 28 37 1 0 0 0
     0 36 48 0 0 0 0
     0 12 15 0 0 0 0
     0 41 46 0 2 1 1
     4 34 33 1 1 0 0
     8 52 57 3 2 2 0
     2 21 35 0 2 1 0
    38 56 67 3 0 3 0
     3 24 30 1 0 0 0
     0 10 21 0 0 0 1
     0 30 42 0 0 0 1
     1 46 54 1 2 2 0
    13 46 68 1 1 4 2
     0 34 38 0 0 2 0
     0 22 25 0 1 1 0
     0 20 29 0 0 0 0
     1 23 30 0 0 1 0
     0 42 55 0 1 1 0
     0 37 47 1 2 3 0
     0 19 32 0 1 0 0
     0 28 33 1 0 1 0
     0 37 31 0 1 1 0
     0 35 47 0 0 1 1
     0 17 19 0 0 1 0
     1 39 49 1 1 1 0
    55 41 53 0 0 1 3
     1 32 40 0 0 0 0
     1  8 11 0 1 0 0
     3 40 47 1 1 2 1
     0 16 20 0 0 1 0
     0 42 59 0 0 0 1
     5 24 33 1 1 1 0
     0 25 35 0 0 2 0
     0 31 35 1 2 2 0
     0 41 58 0 0 1 1
     0 27 35 1 2 1 0
     2 45 54 1 1 2 1
     2 25 39 2 0 1 0
     1 38 54 0 0 1 0
     0 29 38 0 1 1 1
     1 33 43 1 1 0 0
     0 39 44 1 0 1 0
     1 29 32 1 1 1 0
     0 42 46 0 3 3 1
     5 56 71 0 3 3 0
     0 40 50 0 0 1 0
     0 36 60 0 0 0 0
     4 59 57 1 1 1 2
     0 31 40 0 0 0 0
     0 24 29 0 0 1 0
     1 44 50 1 0 0 0
     0 15 21 0 0 1 0
     1 31 47 1 1 0 1
     0 18 20 0 1 0 0
     0 43 50 0 0 2 0
     5 43 50 1 1 1 2
     0 38 52 0 0 0 0
     1 22 22 0 0 2 0
     0 32 36 1 0 0 0
     1 32 44 0 0 0 1
     4 63 75 1 2 1 0
     0 46 57 0 0 2 0
     0 58 68 0 1 0 0
     0 46 52 0 0 0 1
     0 59 68 0 0 0 0
     0 39 43 0 0 0 0
     0 19 22 0 0 0 0
     0 24 39 1 0 1 0
     0 29 38 0 2 2 0
     2 63 79 0 2 2 0
     1 29 39 1 3 0 0
     0 20 24 1 1 1 0
     1 22 46 0 0 0 0
     3 36 59 1 3 2 2
     0 35 67 1 1 1 0
     0 45 38 0 0 1 0
     1 21 27 0 1 1 1
     3 51 52 2 3 2 0
     0 26 21 0 0 0 0
     2 20 19 0 0 0 0
     1 14 19 2 1 1 0
     1 10 14 0 1 3 0
     0  7 12 0 1 1 0
     1 18 25 0 0 0 0
     1  9 20 1 0 1 0
     0 31 31 0 1 1 0
     0 18 22 0 0 1 0
     0 27 24 0 0 0 0
     0 27 38 0 1 1 2
     0 39 44 0 0 1 0
     1 25 29 0 0 1 0
    end

  • #2
    I believe you may have to first store it before estout it?

    Code:
    foreach var of varlist updrs3_total_on updrs3_total_off ///
    updrs1_cogimp_11 updrs1_lighthead_112 updrs1_fatigue_113 updrs2_freezing_213 {
    eststo clear
    eststo: quietly nbreg falls_total `var'
    estout
    }

    Comment


    • #3
      Sorry, I did that, thanks, but I still cannot figure how to export each result into a single table...

      Comment


      • #4
        I think post #2 meant to recommend
        Code:
        eststo clear
        foreach var of varlist updrs3_total_on updrs3_total_off ///
        updrs1_cogimp_11 updrs1_lighthead_112 updrs1_fatigue_113 updrs2_freezing_213 {
        eststo: quietly nbreg falls_total `var'
        }
        estout
        Notice that the eststo clear and estout have been moved outside the loop.

        Comment


        • #5
          Thank you. Darn, this is still not working for me. I get the table below which is for the last variable in the list but I want a tale with all the univariate associations...any ideas?

          -------------------------
          .
          b
          -------------------------
          falls_cate~s
          updrs_all_~l .0359036
          _cons -3.705052
          -------------------------

          Comment


          • #6
            I was not able to replicate the said error in #5. Using William's code and the sample data, I was able to get this:

            Code:
            ------------------------------------------------------------------------------------------
                                 est1         est2         est3         est4         est5         est6
                                    b            b            b            b            b            b
            ------------------------------------------------------------------------------------------
            falls_total                                                                               
            updrs3_tot~n      .069446                                                                 
            updrs3_tot~f                  .0611473                                                    
            updrs1_co~11                               .6113464                                       
            updrs1_l~112                                           -.0605712                          
            updrs1_f~113                                                         .7613604             
            updrs2_f~213                                                                        .73821
            _cons             -1.9567     -2.23872     .1965131      .687948    -.3215061     .1257519
            ------------------------------------------------------------------------------------------
            /                                                                                         
            lnalpha          1.124999     1.083653     1.337544     1.480415     1.262188     1.213963
            ------------------------------------------------------------------------------------------
            Perhaps just try to run a eststo without loop first to make sure the data are good?

            Comment


            • #7
              You might also like to try asdoc for nested regressions
              Code:
              ssc install asdoc
              foreach var of varlist updrs3_total_on updrs3_total_off ///
                      updrs1_cogimp_11 updrs1_lighthead_112 updrs1_fatigue_113 updrs2_freezing_213 {
                      asdoc nbreg falls_total `var', nest tzok
              }
              Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	32.6 KB
ID:	1618596


              You can find more details related asdoc here https://fintechprofessor.com/2018/01/31/asdoc/
              Regards
              --------------------------------------------------
              Attaullah Shah, PhD.
              Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
              FinTechProfessor.com
              https://asdocx.com
              Check out my asdoc program, which sends outputs to MS Word.
              For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

              Comment


              • #8
                I note that the output shown in post #5 (reproduced here using code delimiters [CODE] and [/CODE] for readability)
                Code:
                -------------------------
                                        .
                                        b
                -------------------------
                falls_cate~s  
                updrs_all_~l     .0359036
                _cons           -3.705052
                -------------------------
                suggests that your dependent variable was not falls_total as in your post #1 but rather falls_categories (or something similar), a variable not presented in your example data, and the independent variable for which the coefficient is presented is updrs1_cogimp_11 which is not the last variable in the list in your post #1. From this I conclude that whatever you ran to produce the output in post #5 had varied substantially to the code recommended in post #4, so I am unsurprised that you got an error, which Ken was unable to reproduce.

                Furthermore, the estimates name "." suggests that the code that was run did not successfully use eststo to store the results of each of the regressions, and as a consequence, the estout command presented only the results of the final regression, which were still in memory, giving them the name . because they had not been stored and assigned a name.

                Ken has shown in post #6 that the code in post #4 works when run on your example data. Perhaps you should start from that point, first successfully reproducing the results of post #6, then running the same code on your full dataset, and if that works, then modifying it suitably for the new set of models that led to post #5.

                Comment

                Working...
                X