Announcement

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

  • storing -egen varlist- after each regression

    Consider the following panel dataset:
    id datadate affiliation revenue workforce
    100 31-May-01 NBA 200 11
    100 31-May-02 NBA 250 15
    101 31-May-03 NHL 900 20
    101 31-May-01 NFL 932 9
    102 31-May-02 NHL 400 65
    103 31-May-03 FIFA 230 25
    103 31-May-04 FIFA 890 28
    I am running the following regression:

    Code:
    reg revenue workforce
    After this regression, I would like to count distinct affiliation and ids in and out of my regression sample, and this is my code:

    Code:
    egen distinct_id = group(id) if e(sample)
    egen distinct_affiliation = group(affiliation) if e(sample)
    sum distinct_id distinct_affiliation
    My understanding is that the "max" of the -sum- gives you the distinct counts for each variable of my interest.

    I am running several regressions (approx. 30), but after each regression, I would like to store the "max" number from the sum and export to Excel as csv or xlsx file.

    Do you know what is the best way to go about doing this?

  • #2
    Using
    Code:
    gen max=`r(max)'
    after the sum command, you save the maximum value in a variable.

    Comment


    • #3
      Great, thanks.

      How would I store -max- in some sort of a matrix and export to csv?

      Originally posted by Demetrio Guzzardi View Post
      Using
      Code:
      gen max=`r(max)'
      after the sum command, you save the maximum value in a variable.

      Comment


      • #4
        Hmmm, the command does not work to store the information...any other suggestions?
        How can I store this information and export to Excel?

        Originally posted by Demetrio Guzzardi View Post
        Using
        Code:
        gen max=`r(max)'
        after the sum command, you save the maximum value in a variable.

        Comment


        • #5
          You show only 1 regression and there is no scope to loop your code. Spend more time creating a reproducible example with at least 2 regressions and specify exactly what statistics you want. Also, see FAQ Advice #12 on how to use the dataex command to present data examples.

          Comment


          • #6
            Hi Andrew,

            This is helpful. I will use -dataex- and put a proper formatted data when asking a question.

            Thanks!

            Originally posted by Andrew Musau View Post
            You show only 1 regression and there is no scope to loop your code. Spend more time creating a reproducible example with at least 2 regressions and specify exactly what statistics you want. Also, see FAQ Advice #12 on how to use the dataex command to present data examples.

            Comment

            Working...
            X