Announcement

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

  • estimate store error "last estimation results not found, nothing to store"

    I tried to re-run an older file (dating to 2020) that estimated means, stored the results, and utilized them in the coefplot procedure. But I now get an error that I don't recall getting before. The setup is simple:

    use https://www.stata-press.com/data/r17/auto
    sum price mpg rep78 if foreign==1
    estimate store m1



    This returns:

    . sum price mpg rep78 if foreign==1

    Variable | Obs Mean Std. dev. Min Max
    -------------+---------------------------------------------------------
    price | 22 6384.682 2621.915 3748 12990
    mpg | 22 24.77273 6.611187 14 41
    rep78 | 21 4.285714 .7171372 3 5

    . estimate store m1
    last estimation results not found, nothing to store
    r(301)
    ;



    I'm guessing that I'm missing something simple. Any advice welcome.

  • #2
    no error when I do it. (Stata 17)

    Comment


    • #3
      The -summarize- command does not leave anything behind that Stata calls "estimates." Stata uses the term "estimates" to refer specifically to the output of regression commands and certain others such as -factor-.

      The results produced by -summarize- are temporarily stored in -r()-. But they will be erased by any subsequent commands that also store results in -r()-, which, by the way, is most commands. Moreover, because you have invoked -summarize- with multiple variables, only the results for the last of those will appear in -r()-; the others have been lost and are only available in the Results window for your eyes.
      Code:
      . sysuse auto, clear
      (1978 automobile data)
      
      .
      . sum price mpg rep78 if foreign == 1
      
          Variable |        Obs        Mean    Std. dev.       Min        Max
      -------------+---------------------------------------------------------
             price |         22    6384.682    2621.915       3748      12990
               mpg |         22    24.77273    6.611187         14         41
             rep78 |         21    4.285714    .7171372          3          5
      
      .
      . return list
      
      scalars:
                        r(N) =  21
                    r(sum_w) =  21
                     r(mean) =  4.285714285714286
                      r(Var) =  .5142857142857143
                       r(sd) =  .7171371656006362
                      r(min) =  3
                      r(max) =  5
                      r(sum) =  90
      If you need to save these results for several variables for later use, then I can suggest two approaches.

      1. Use the -collapse- command to create a data set with the statistics, and save the results in a temporary or permanent data set, which you can then access as needed using -merge- or with -frame-s.

      2. Or, you can write code to save them in local macros. Something like:
      Code:
      foreach v of varlist price mpg rep78 {
          summ `v' if foreign == 1
          foreach x in N mean sd min max {
              local `v'_`x' = r(`x')
          }
      }
      The corresponding results will now be available in the appropriately named local macros.

      Note: you can also store the Var and sum, and sum_w: I didn't show that because Var and sum can be calculated from the others, and there were no weights in the original summarize command to make sum_w any different from sum.

      Added: I cannot replicate the findings of #2.
      Code:
      . about
      
      Stata/MP 17.0 for Windows (64-bit x86-64)
      Revision 10 Jan 2023
      Copyright 1985-2021 StataCorp LLC
      
      Total physical memory:       32.00 GB
      Available physical memory:   18.55 GB
      
      Stata license: Single-user 4-core  perpetual
      Serial number: REDACTED
        Licensed to: Clyde Schechter
                     Albert Einstein College of Medicine
      
      . sysuse auto
      (1978 automobile data)
      
      . sum price mpg rep78 if foreign == 1
      
          Variable |        Obs        Mean    Std. dev.       Min        Max
      -------------+---------------------------------------------------------
             price |         22    6384.682    2621.915       3748      12990
               mpg |         22    24.77273    6.611187         14         41
             rep78 |         21    4.285714    .7171372          3          5
      
      . estimates store m1
      last estimation results not found, nothing to store
      I suspect that George Ford had some estimation results from a previously run estimation command still in memory, that the -estimates store m1- command then picked up. But when you don't start with any estimation results in memory, you can't run -estimates store-.
      Last edited by Clyde Schechter; 26 Jan 2023, 12:56.

      Comment


      • #4
        Can also use

        tabstat x y z, save stats(mean sd N)

        which puts the stats of interest in a matrix.

        Comment


        • #5
          I ran the following and it reproduced the full table for the three variables.

          Code:
          sum price mpg rep78 if foreign==1
          estimates store m1
          return list
          summ mpg // refills the return info
          estimates restore m1
          estimates replay m1
          Not sure why you are getting an error.

          Comment


          • #6
            I would be more convinced by post #5 if (a) the code used were
            Code:
            which sum
            clear all
            sysuse auto, clear
            sum price mpg rep78 if foreign==1
            ereturn list
            estimates store m1
            return list
            summ mpg // refills the return info
            estimates restore m1
            estimates replay m1
            and (b) the code and output were copied from the Results window and included in the post.
            Code:
            . which sum
            built-in command:  summarize
            
            . clear all
            
            . sysuse auto, clear
            (1978 automobile data)
            
            . sum price mpg rep78 if foreign==1
            
                Variable |        Obs        Mean    Std. dev.       Min        Max
            -------------+---------------------------------------------------------
                   price |         22    6384.682    2621.915       3748      12990
                     mpg |         22    24.77273    6.611187         14         41
                   rep78 |         21    4.285714    .7171372          3          5
            
            . ereturn list
            
            . estimates store m1
            last estimation results not found, nothing to store
            r(301);

            Comment


            • #7
              Hah. After a reboot, I get the error. Very strange. In any case, it should not work, but seemed to work yesterday. replay returned the summ table. Strange.

              Comment


              • #8
                Any word on this? I get the same error. I've tried clearing everything (ereturn list, return list), restarting Stata, and anything stored in estimates. I only seem to get this error when I use summarize or tabstat. When I try to store regression results, it works properly.
                For example,

                use https://www.stata-press.com/data/r17/auto
                reg price mpg if foreign==1
                estimate store m1


                does not give an error, and when I run `estimates replay m1`, it properly replays the regression results.

                Also, if you run a regression, store the results, and then try to use `summarize` and store the results as m2, it doesn't throw the error, but then when you run `estimates replay m1 m2` it just displays m1 results (the regression results) twice. Below is the code you can use to replicate this error:

                sysuse auto, clear
                reg price mpg
                estimates store m1
                sum price
                estimates store m2
                estimates replay m1 m2

                I have this version of Stata:

                Stata/BE 17.0 for Windows (64-bit x86-64)
                Revision 10 Jan 2023
                Last edited by Sophie Andrews; 22 Mar 2023, 21:00.

                Comment


                • #9
                  Also, if you run a regression, store the results, and then try to use `summarize` and store the results as m2, it doesn't throw the error, but then when you run `estimates replay m1 m2` it just displays m1 results (the regression results) twice.
                  This is not an error. This is exactly how it is supposed to work. -reg price mpg- creates a set of estimates in e(), which are then stored as m1 with the -estimates store m1- command. The next command, -sum price- leaves results in -r()-, but does nothing whatsoever to e(). The estimates from the -reg price mpg- command are still there: -sum- does not clear them, nor does it add anything to them or change them in any way. So when you run -estimates store m2-, those same, unchanged results, are stored again, this time under the name m2. Consequently -estimates replay m1 m2- shows the same result twice, because the results in m1 and m2 are both just the original estimates from -reg price mpg-.

                  Comment


                  • #10
                    Thanks for clarifying, Clyde! I see now that `estpost` can save summarize and tabstat results (and that eststo is reserved for regression estimates, if I understand correctly).

                    Comment


                    • #11
                      Originally posted by Sophie Andrews View Post
                      Any word on this? I get the same error. I've tried clearing everything (ereturn list, return list), restarting Stata, and anything stored in estimates. I only seem to get this error when I use summarize or tabstat. When I try to store regression results, it works properly.
                      For example,

                      use https://www.stata-press.com/data/r17/auto
                      reg price mpg if foreign==1
                      estimate store m1


                      does not give an error, and when I run `estimates replay m1`, it properly replays the regression results.

                      Also, if you run a regression, store the results, and then try to use `summarize` and store the results as m2, it doesn't throw the error, but then when you run `estimates replay m1 m2` it just displays m1 results (the regression results) twice. Below is the code you can use to replicate this error:

                      sysuse auto, clear
                      reg price mpg
                      estimates store m1
                      sum price
                      estimates store m2
                      estimates replay m1 m2

                      I have this version of Stata:

                      Stata/BE 17.0 for Windows (64-bit x86-64)
                      Revision 10 Jan 2023
                      Have a look at estpost (estout) by Benn Jann from SSC that will allow you to post results of summarize and some other r class commands to e().
                      http://repec.org/bocode/e/estout/estpost.html

                      This allows you to have


                      Code:
                      eststo m2: estpost summarize ...
                      Last edited by Andrew Musau; 23 Mar 2023, 09:48.

                      Comment

                      Working...
                      X