Announcement

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

  • Issues with eststo

    I am running a bunch of regressions in a loop and am storing them using eststo. This works like a charm, but as my loops become many and large, I consistently run into two problems:

    1) The eststo names get too long as I add more and more loops. The error message looks like this:
    _est_example_reallylongeststonamethatisreallylong invalid name
    r(7);

    2) I can only store 300 estimates. The error message looks like this:
    system limit exceeded
    you need to drop one or more models
    --(then it lists the models I have stored)--
    r(1000);

    My question is if it is possible to allow for longer eststo names, and if I can increase the 300 limit to a larger number. If not, is there another way to store hundreds of estimation results with (effectively) no limits on name lengths?
    Last edited by Samuel Barker; 07 Apr 2020, 12:56.

  • #2
    Samuel,

    It always helps to see the code and the error directly, i.e., exactly what your loop is and exactly what the error is. Even better is to replicate the problem on a sample dataset that everyone on the list has access to.

    1. Without seeing your code, I don't know exactly what the problem might be but you could assign the models names that are shorter.
    Code:
    eststo m1: reg ...
    eststo m2: reg...
    eststo m3: reg...
    2. I searched quickly for this problem and came up with the following Statalist post...

    https://www.statalist.org/forums/for...-store-results

    I think you might find a solution to this problem there.

    hth,
    Lance

    Comment


    • #3
      Stata names are limited to 32 characters, so you need some other way of naming your estimates. There is no obvious way to increase the limit of 300 to a larger number.

      You can overcome both these issues by storing your estimates in a file, along the lines of the following code
      Code:
      sysuse auto, clear
      forvalues i=1/400 {
          quietly reg length weight
          quietly estimates save "gnxl", append
      }
      estimates use  "gnxl", number(399)

      Comment


      • #4
        Thanks for the replies!

        I will take a look at the post you mentioned, Lance.


        Apologies for not including some code for reference. The code below replicates the errors I am encountering and hopefully highlights why this is an issue for me.

        Code:
        sysuse auto, clear
        foreach loop1 in l1_1 l1_2 l1_3 {
                foreach loop2 in l2_1 l2_2 l2_3 {
                        foreach loop3 in l3_1 l3_2 l3_3 {
                                foreach loop4 in l4_1 l4_2 l4_3 {
                                        foreach loop5 in l5_1 l5_2 l5_3 {
                                                foreach loop6 in l6_1 l6_2 l6_3 {
                                                        foreach loop7 in l7_1 l7_2 l7_3 {
                                                                qui reg price mpg
        
                                                                * Uncomment for error from eststo invalid name.
                                                                * eststo `loop1'`loop2'`loop3'`loop4'`loop5'`loop6'`loop7'
        
                                                                * Uncomment for error from too many stored estimates.
                                                                * eststo
                                                        }   
                                                }   
                                        }   
                                }   
                        }   
                }   
        }
        I cannot really make my names shorter, unfortunately. In my code, most of the locals from the loops are only 2 or 3 characters. They are already almost unmeaningful, but I can still easily reference a specific regression this way. For example, in my code I have a loop for fixed effects, and a loop for stratifying (as well as a bunch of other loops: changing the covariates, stratifying differently, etc. for robustness checking). Those loops look like this:
        Code:
        foreach fe_yn in yfe nfe { \\ where yfe has a fixed effect and nfe does not.
            foreach blstratify in abl bbl tbl { \\ where  tbl is the total sample, abl is the sample with above average baseline, and bbl has below average baseline
                * regression stuff
                eststo outcome_`fe_yn'_`blstratify'
             }
        }
        Later on, I would like to be able to pull the specific regression into esttab, like this:
        Code:
        esttab outcome_yfe_abl outcome_yfe_bbl using example, replace
        Using the approach you suggested, William, makes it look like I would need to reference a regression using a number. Is that correct? Is there a way to pass a name to a specific regression?

        Comment


        • #5
          You could store each set of estimates in a separate file. Limitations on filenames are imposed by your operating system, not by Stata.

          Comment


          • #6
            Here's a possibility that leverages William's suggestion. The idea is to create a series of global macros whose name is what you want the model to be called and make the value of the global be equal to the number that identifies the model in the saved estimates. I don't know if esttab can capture estimates from inside a file so, after the loop, you store the estimates using the eststo prefix and give the model a name as you call them with estimates use.

            Code:
            sysuse auto, clear
            local i = 1
            foreach loop1 in l1_1 l1_2 l1_3 {
                foreach loop2 in l2_1 l2_2 l2_3 {
                    foreach loop3 in l3_1 l3_2 l3_3 {
                        foreach loop4 in l4_1 l4_2 l4_3 {
                            foreach loop5 in l5_1 l5_2 l5_3 {
                                foreach loop6 in l6_1 l6_2 l6_3 {
                                    foreach loop7 in l7_1 l7_2 l7_3 {
                                        global `loop1'`loop2'`loop3'`loop4'`loop5'`loop6'`loop7' = `i'
                                        qui reg price mpg
                                        qui estimates save "gnxl", append
                                        local ++i
                                    }   
                                }   
                            }   
                        }   
                    }   
                }   
            }
            
            eststo m1: estimates use "gnxl", number(${l1_1l2_1l3_1l4_1l5_1l6_1l7_1})
            eststo m2: estimates use "gnxl", number(${l1_1l2_1l3_1l4_1l5_1l6_1l7_2})
            esttab m1 m2
            This all feels quite clumsy to me though.

            Lance

            Comment


            • #7
              Thanks, Lance! It isn't pretty, but it works and that is all I need right now.

              Thank you guys for all the help!

              Comment

              Working...
              X