Announcement

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

  • How can i create a loop for each variable on stata?

    I'm on a portfolio analysis, so I import an excel spreadsheet where the first column stand for Date of observation, from column B to column ABQ there are historical returns series for firms, one column per firm.
    I need a loop in order to compute OLS coefficient and perform inferential analysis. rm is my indipendent variable. After that, how may I save coefficient for each company in order to study a portfolio coefficient?

  • #2
    HTML Code:
    https://stats.oarc.ucla.edu/stata/modules/working-across-variables-using-foreach/

    Comment


    • #3
      No doubt the code that was linked to in #2 will answer your question. But it sounds to me like you shouldn't be approaching the problem this way in any case. I would -reshape- the data to long layout and then use either -rangestat- (SSC) or -statsby (official Stata command) to run the regressions for each firm separately.

      More generally, there isn't much data management or analysis that works best with wide data in Stata. In fact, somethings are not even possible in wide data. When you are given a data set in wide layout, especially if it is panel data, your first instinct should be to reshape it to long layout. You will almost never go wrong that way.

      Comment

      Working...
      X