Announcement

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

  • Loop regression per fund identifier

    Hello everyone,

    I am working on a project with panel data. I am trying to identify the difference in performance of green and conventional mutual funds. In my data sample around 200 green and 400 conventional funds are included. I want to calculate the Betas and Alphas of every fund, using the four factor model. However, to do 600 seperate regressions for each fund is going to be very time consuming. So I was wondering if anyone could help me with a STATA command which loops through the data and stores the different alphas and betas.

    This is what i have so far, but it doesn't seem to change per FundIdentifier:

    foreach i in FundIndentifier {
    regress Excess Ret MKT SMB HML MOM
    }

    I hope anyone can help me out with this issue.
    Thank you very much,
    Fabian
    Last edited by Fabian Brand; 16 Jan 2018, 07:01.

  • #2
    Assuming that you typed foreach not Foreach that's just the same regression, repeated, except repeated only once.

    Many, many such questions here. Good search terms are runby and statsby and rangestat

    Comment


    • #3
      I have looked through this forum for a while, before asking this question. Unfortunately, all attempts on using suggestions on other posts for my own problem have not been successful.
      Thank you for the suggested search terms. I will look into it

      Comment


      • #4
        I have researched this issue for about a day now. Even the proposed search terms have not gotten me to the right answer yet. I am a beginner in working with STATA, making being creative with the program very difficult.

        Help would be highly appreciated.
        Thank you

        Comment


        • #5
          You've posted just one code example and I've explained why it doesn't do what you want. Otherwise we can't comment on what you don't show us.

          Conversely, there are probably hundreds of relevant posts. Here is one such thread: https://www.statalist.org/forums/for...tas-for-stocks (later posts are more relevant).

          Comment


          • #6
            To show that I have been trying extensively, here are my attempts:



            foreach i in FundIdentifer {
            reg ExcessRet ExcessReturnontheMarket
            matrix betas=nullmat(beta) \ e(b)
            matrix r2=nullmat(r2), e(r2)
            matrix s2=nullmat(s2), e(V)
            }

            foreach i in FundIdentifier if SRI == 1 {
            xtile portfolioSRI= cond(FundIdentifier==i,.), nq(1)
            }

            foreach i in FundIdentifier {
            display Date
            }

            forvalue i = 1(1)91139 {
            foreach i in FundIdentifier {
            reg ExcessRet ExcessReturnontheMarket if FundIdentifier == `i'
            }
            }

            tempname myresults2
            postfile `myresults2' threshold intercept gradient se using myresults2.dta
            quietly forvalue x = 1(1)91139 {
            xi: regress ExcessRet ExcessReturnontheMarket if FundIdentifier < `x'
            post `myresults2' (`x') (`=_b[_cons]') (`=_b[ExcessReturnontheMarket]') (`=_se[ExcessReturnontheMarket]')
            }
            postclose `myresults2'
            use myresults2
            list

            capture program drop one_regression
            program define one_regression
            regress ExcessRet ExcessReturnontheMarket
            foreach v of varlist ExcessReturnontheMarket {
            gen b_`v' = _b[`v'}
            }
            gen n= e(N)
            exit
            end
            runby one_regression, by(FundIdentifier) status









            However, none of these codes have been successful in getting is a different regression for every fund.

            Looking forward to your response
            Fabian

            Comment

            Working...
            X