Announcement

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

  • Extracting regression coefficient values

    Hallo everyone:

    I want to run regression for all firms in industry i to estimate specific regression coefficients for each industry. That's my very short example data set:

    Code:
    obs firm_id industry  y   x1    x2    x3
    1    314      1      3.1  2.0  19.1   0.4
    2    314      1      0.9  2.3  11.4   0.5
    3    319      1      etc
    4    401      2
    5    408      2
    6    409      3
    7    409      3
    I tried the following code:

    Code:
    sum industry
    scalar a=r(min)
    scalar b=r(max)
    
    forvalues c=`=scalar(a)'/`=scalar(b)' {
    qui reg y x1 x2 x3 if industry==`c'
    capture noisily mat beta=e(b)
    capture noisily svmat double beta, name(var_`c')
    }
    What I want to achieve are 4 variables wit the regression coefficient values (x1 x2 x3 intercept) by industry. However, my code generates 4 variables for every industry with the coefficient values only in the first observations; the data editor looks like:
    Code:
    obs firm_id industry  y   x1    x2    x3  var_11  var_12  var_13  var_14  var_21  var_22  var_23 var_24  var_31  var_32  var_33  var 34
    1    314      1      3.1  2.0  19.1   0.4  0.78    0.13    0.78    0.64    0.69    0.20    0.51    0.64    0.83    0.03    0.78    0.44
    2    314      1      0.9  2.3  11.4   0.5    .      .        .       .       .       .       .       .       .       .       .       .
    I hope this explanation is understandable. Does anyone have an idea how to solve this problem, maybe with a combination of replace and svmat? I haven't found any working solution for this.

    Thank you!
    TM

  • #2
    Code:
    help statsby

    Comment


    • #3
      Sometimes it's that easy ... Thank you, Nick!

      Comment

      Working...
      X