Announcement

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

  • Pulling constant from regsave command

    Hi all,

    I am using the regsave command to generate a dataset with a list of statistics that I plan to later use for creating some graphs. I am using this command to create a Stata dta, not a table.

    I am running
    Code:
     regsave using outcomes, append addlabel(year, Y`n', outcome, attendance)
    which gives me a set of statistics (see below) but does not include the constant term associated with each regression. I was wondering if there is an easy way to include this term in my dta.

    This is what my data looks like
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str2 var float(coef stderr) int N float r2 str2 year str10 outcome
    "Du" .04910912 .031895615 6721 -.003773775 "Y7" "graduation"
    "Dn" .1635283 .06579578 6721 -.003773775 "Y7" "graduation"
    "Du" .035434615 .027076364 8574 -.004120412 "Y6" "graduation"
    "Dn" .15168454 .04944327 8574 -.004120412 "Y6" "graduation"
    "Du" .02645824 .025441853 8574 -.00552487 "Y5" "graduation"
    "Dn" .1584202 .04947082 8574 -.00552487 "Y5" "graduation"
    "Du" .02148266 .02088279 8574 -.0016554584 "Y4" "graduation"
    "Dn" .05769655 .04812319 8574 -.0016554584 "Y4" "graduation"
    "Du" .03529666 .023826674 6721 .0004097005 "Y7" "attendance"
    "Dn" -.005854927 .04485578 6721 .0004097005 "Y7" "attendance"
    "Du" .05378525 .022395836 8574 -.0001227465 "Y6" "attendance"
    "Dn" .032865014 .036374215 8574 -.0001227465 "Y6" "attendance"
    "Du" .0324158 .026787754 8574 .0009376752 "Y5" "attendance"
    "Dn" .06649923 .04469869 8574 .0009376752 "Y5" "attendance"
    "Du" .05486205 .03121347 8574 -.0027902916 "Y4" "attendance"
    "Dn" .13864861 .0480488 8574 -.0027902916 "Y4" "attendance"
    "Du" .04672282 .031793423 8574 -.001970332 "Y3" "attendance"
    "Dn" .1180051 .04745502 8574 -.001970332 "Y3" "attendance"
    "Du" .05682012 .032604184 8574 -.00305105 "Y2" "attendance"
    "Dn" .13746797 .04748501 8574 -.00305105 "Y2" "attendance"
    "Du" .04196186 .032960717 8574 -.002764723 "Y1" "attendance"
    "Dn" .13095056 .04723534 8574 -.002764723 "Y1" "attendance"
    end
    Thank you!
    Astrid
    Last edited by Astrid Pineda; 05 Feb 2022, 06:45.

  • #2
    I do not use regsave (SSC), but here is a program that will store the results of a regression including constant in a frame named reg2dta.

    Code:
    cap program drop reg2dta
    program define reg2dta, eclass
    cap frame drop reg2dta
    frame create reg2dta
    mat res= (r(table)[1..6, 1...])'
    local cols: coln res
    local rows: rown res
    frame reg2dta{
        svmat res
        rename (res1-res6) (`cols')
        gen varname=""
        forval i=1/`=wordcount("`rows'")'{
            replace varname = "`=word("`rows'", `i')'" in `i'
        }
        order varname
    }
    end
    
    sysuse auto, clear
    regress mpg weight turn i.rep78 disp gear, robust
    reg2dta
    frame reg2dta: l, sep(0)
    Res.:

    Code:
    . frame reg2dta: l, sep(0)
    
         +------------------------------------------------------------------------------------+
         |      varname           b         se           t     pvalue          ll          ul |
         |------------------------------------------------------------------------------------|
      1. |       weight   -.0053298   .0019598   -2.719572    .008537     -.00925   -.0014096 |
      2. |         turn   -.1934728   .1718392   -1.125895   .2646934   -.5372024    .1502567 |
      3. |     1b.rep78           0          .           .          .           .           . |
      4. |      2.rep78   -.3893617   1.539953     -.25284   .8012561   -3.469727    2.691004 |
      5. |      3.rep78   -.9689192   1.405318   -.6894661    .493188   -3.779974    1.842136 |
      6. |      4.rep78   -1.341048   1.423618   -.9419997   .3499703   -4.188707    1.506612 |
      7. |      5.rep78    1.591763   2.452763    .6489672    .518836   -3.314494     6.49802 |
      8. | displacement    .0136819   .0144645    .9458956   .3479957   -.0152514    .0426153 |
      9. |   gear_ratio    1.713841   1.832977    .9350039   .3535342   -1.952659    5.380341 |
     10. |        _cons    37.86281   7.600388    4.981695   5.65e-06    22.65977    53.06585 |
         +------------------------------------------------------------------------------------+

    Comment


    • #3
      regsave (SSC) should work fine; without seeing a minimum working example I cannot say more. Here is an example showing that it works:
      Code:
      sysuse auto, clear
      reg price mpg
      regsave
      list
      Results:
      Code:
           +----------------------------------------------+
           |   var        coef     stderr    N         r2 |
           |----------------------------------------------|
        1. |   mpg   -238.8943   53.07669   74   .2195829 |
        2. | _cons    11253.06   1170.813   74   .2195829 |
           +----------------------------------------------+
      Associate Professor of Finance and Economics
      University of Illinois
      www.julianreif.com

      Comment

      Working...
      X