Announcement

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

  • Using regression coefficients as variables

    Hi, I have panel data with information on N people over T periods. I need to add two columns to my database as follows: First, run simple regressions for each person using two explanatory variables (that is the easy part). Then, use the coefficients of these regressions (say, Bn1 and Bn2) as observations in my database. In other words, I should end up with two new columns that contain the same values within people but different ones across people. Thanks in advance.

  • #2
    The Grunfeld dataset is a firm-level panel dataset, so the following should be illustrative.

    Code:
    webuse grunfeld, clear
    gen BN1=.
    gen BN2=.
    levelsof company, local(companies)
    foreach c of local companies{
        regress invest kstock if company==`c'
        replace BN1=_b[kstock] if company==`c'
        regress invest mvalue if company==`c'
        replace BN2=_b[mvalue] if company==`c'
    }

    Comment


    • #3
      Thanks, Andrew. It worked perfectly.

      Comment

      Working...
      X