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

  • Running multiple regressions at the same time

    Hello everyone, I am new to Stata and I cannot find the right code to solve my issue.

    I have time series data and I want to use fund's returns as dependent variable and some factors as indipendent variables. Given the fact that I have hundreds of funds, I would lose a lot of time performing each regression manually. Is possible fixing the indipendent variables, performing the regression for each fund automatically and saving the output?

    Thank you.

  • #2
    Mark: If I understand your question correctly, then using a -foreach- loop may work. For instance, if your dependent variables are y1, y2, ..., y1000, your RHS variables are x1 and x2, and using -regress- as an estimation method as an example (you would choose the estimation method and options best suited for your time-series data and substitute these for the -regress- command), then
    foreach y of varlist y1-y1000 {
      regress `y' x1 x2
    If this is more-or-less what you have in mind, then I might suggest familiarizing yourself with the different ways -foreach- can work:
    help foreach
    and how to specify -varlists-
    help varlist
    The next question is what you mean by "saving the output." If you mean simply having a log file that contains the results, then check out
    help log
    If you mean actually preserving the regression output (e.g. the estimated parameters) for subsequent computations, then there are lots of options to consider.


    • #3
      John gives excellent advice for the situation in which funds define separate variables. Alternatively if you have a panel structure, check out statsby and rangestat (SSC).


      • #4
        following John's comments, i suggest you to use post to save your estimation result one by one from the foreach loop