Announcement

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

  • Estout: saving results with panel data

    Hi all,

    I'm running a regression on panel data, where I want the regression to be run separately on each catagory (Fullid):

    Code:
    bysort Fullid: regress height sign
    I know that my regression is working because I can see the table results as they pop up in Stata. However, when I got to save them using:

    Code:
    esttab using "results", rtf replace
    I end up with only the final regression result (ex. the result of the regression on the last category). Does anyone have advice on how to get the results to save for each category that I run the regression for?

    Thank you!


  • #2
    estout is from Stata Journal, as you are asked to explain in FAQ Advice #12.

    Code:
    eststo clear
    bysort Fullid: eststo: regress height sign
    esttab using "results", rtf replace
    esttab est* using "results", rtf replace

    Comment


    • #3
      Hi Andrew,

      Thanks for your help with this. I changed the file to .csv but otherwise only adjusted slightly:

      I found it worked just the same as if I ran:
      Code:
      eststo clear
      bysort Fullid: eststo: regress height sign
      esttab using "results.csv", replace
      Two follow-up questions:

      1. How can I include the r2 measure for each these?
      2. Is there a way to have my Id variable listed in my results? I've got 103 regression results but they're labeled (1) (2) (3)... (103), it would be ideal if I could label them their Fullid.

      Comment


      • #4
        This assumes that all regressions are successful, i.e., there are no -no observations- errors. Additionally, the id variable is all numeric or all string with no spaces. If it is a string+ numbers, id10 will be sorted before id2-id9 as alphabetically, it starts with 1. On the other hand, the esttab command will group these ids following their numeric sequence, and the labels will thus be wrong. The model titles will be your identifiers.

        Code:
        levelsof Fullid, local(myids)
        eststo clear
        foreach id of local myids{
            regress height sign if Fullid==`id'
            est sto id`id'
          
        }
        esttab id*, stats(r2, labels("R-squared")) nonumbers mtitles(`myids')
        Last edited by Andrew Musau; 08 Sep 2020, 15:42.

        Comment


        • #5
          Hi Andrew,

          I tried your code, but I can't get it to save anywhere.

          I tried adding:
          Code:
           esttab id*, stats(r2, labels("R-squared")) nonumbers mtitles(`myids')using "results.csv", replace 
          When I type that, the error code: r(198) "invalid 'replace'" comes up.

          How can I save it elsewhere? I don't really know if the code works in terms of applying model titles because none those usually appear for me until exported.
          Last edited by Kate Pryce; 08 Sep 2020, 15:49.

          Comment


          • #6
            Remove the comma before replace as you already have one.

            Code:
            esttab id* using "results.csv", replace stats(r2, labels("R-squared")) nonumbers mtitles(`myids')

            In Stata, all options follow the comma. Here, -using myfile.csv- is part of the command and not an option.
            Last edited by Andrew Musau; 08 Sep 2020, 16:14.

            Comment


            • #7
              Hi Andrew,

              Thanks for that tip. That'll be really helpful as I keep using stata.

              However, when I changed the code as your suggested I ended up with the same results 103 times over, and, unfortunately each was still titled (1) (2) (3)...etc.

              Is there a different command that pulls full regression results directly from stata into excel or word or an rtx file? I'd just like the coefficient, constant, R2 and number of observations.

              Comment


              • #8
                However, when I changed the code as your suggested I ended up with the same results 103 times over, and, unfortunately each was still titled (1) (2) (3)...etc.
                I edited the code in #4 because I had left out -if Fullid==`id'- from the fourth line, so check out whether this is the cause.


                Is there a different command that pulls full regression results directly from stata into excel or word or an rtx file? I'd just like the coefficient, constant, R2 and number of observations.

                It is possible to write your own program, but esttab is more efficient and makes this unnecessary. My guess is that you have a numeric variable with value labels, so you are interested in seeing the labels and not the values. If you give a data example using dataex depicting your data - about 3 ids should do- then it will be easier to write code that does exactly what you want.

                Comment

                Working...
                X