Announcement

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

  • Extract the constant (_cons) and the regression coefficients of multiple regressions and display results in a table

    Dear team,

    I have the variables v1-v1553, which I like to regress with one variable mktrf. My code looks like this:

    foreach x of varlist v1-v1553 {
    regress `x' mktrf
    }

    From every regression, I'd like to save the regression coefficient (mktrf) and the constant (_cons) and display the results in a clear manner.

    With this code, i'm getting the results, but in this display I can't use it:

    . foreach x of varlist v1-v1553 {
    2. quietly: reg `x' mktrf
    3. matrix list e(b)
    4. }

    e(b)[1,2]
    mktrf _cons
    y1 -.88101135 239.65107

    e(b)[1,2]
    mktrf _cons
    y1 -30.911128 4256.2663

    ......

    I'm also not sure, if matrix is the best way, because with my version I can only built matrices with 800 rows. Is there a table command maybe, which displays the results properly?

    This didn't work as well:

    . foreach x of varlist v1546-v1549 {
    2. table (result) (colname), command(_r_b: regress `x' mktrf) append
    3. }

    ------------------------------------
    | v1547 Mkt-RF
    ------------+-----------------------
    Coefficient | -.1639949 -1.050174
    ------------------------------------

    ------------------------
    | v1547
    ------------+-----------
    Coefficient | -.1639949
    ------------------------

    ------------------------
    | v1547
    ------------+-----------
    Coefficient | -.1639949
    ------------------------


    Best
    Julius

  • #2
    There is never going to be a clean way to present 1,553 regressions in one table. So the first question to you is going to be: Why would you want to do that?
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you for the fast replay! Every variable is the Total Return-risk free return of a stock. By regressing those variables with the market factor (variable "mktrf"), I can calculate the Jensen's Alpha and the Beta of each stock. Is there a smarter way?

      regards
      Julius

      Comment


      • #4
        Code:
        clear all                      // all is necessary
        sysuse nlsw88                  // open example data
        unab varlist : hours-tenure    // list of variables
        
        // create a new frame (dataset) to store the coefficients
        frame create coefs str20 var float(cons coef)  
        
        // fill that frame with the coefficients
        foreach var of local varlist {
            // estimate the model
            capture reg `var' wage
            // store the coefficients
            frame post coefs ("`var'") (_b[_cons]) (_b[wage])
        }
        // go to the frame with the coefficients
        frame change coefs
        // look at (if you want) you could also plot it, or do other computations on it
        list
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          Dear Maarten,

          thank you so much for your help! It worked perfectly!

          Best
          Julius

          Comment

          Working...
          X