Search code examples
statafinancequantitative-finance

Extract intercepts from multiple regressions in stata


I am attempting to reproduce the following in stata. This is a scatter plot of average portfolio returns (y axis) and predicted retruns (x axis).

enter image description here

To do so, I need your help on how I can extract the intercepts from 25 regressions into one variable? I am currently running the 25 portfolio regressions as follows. I have seen that parmest can potentially do this but can't get it to work with the forval. Many thanks

    forval s = 1 / 5 {
    forval h = 1 / 5 {
        reg S`s'H`h' Mkt_Rf SMB HML 

        }
    }

Solution

  • I don't know what your data look like, but maybe something like this will work:

    gen intercepts = .
    local i = 1
    forval s = 1 / 5 {
        forval h = 1 / 5 {
            reg S`s'H`h' Mkt_Rf SMB HML 
    
            // assign the ith observation of intercepts
            // equal to the regression constant
            replace intercepts = _b[_cons] if _n == `i'
    
            // increment i
            local ++i
        }
    }