Announcement

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

  • Capturing regression coefficients as variables for use in an index

    Hi Statalist,

    I am currently working on a project in an econometrics class to model home price returns over a period of time and am trying to construct an index with the following form:

    I_k^H=100*e^(β_k )

    for all k ∈{1967,1968,...1999,2001,2018}

    I first created dummy variables for each year with the following:

    Code:
    tab yy, gen(Dyy)
    I am struggling to create the (β_k) term with STATA even though I have generated each of the coefficients I need with the following regression.

    Code:
    reg lprice age age2 twnhome acres acres2 sfla rmbed bath bath2 dist dist2 Dyy1 Dyy2
    Dyy3 Dyy4 Dyy5 Dyy6 Dyy7 Dyy8 Dyy9 Dyy10 Dyy11 Dyy12 Dyy13 Dyy14 Dyy15 Dyy16
    Dyy17 Dyy18 Dyy19 Dyy20 Dyy21 Dyy22 Dyy23 Dyy24 Dyy25 Dyy26 Dyy27 Dyy28 Dyy29
     Dyy30 Dyy31 Dyy32 Dyy33 Dyy35 Dyy36 Dyy37 Dyy38 Dyy39 Dyy40 Dyy41 Dyy42 Dyy43
    Dyy44 Dyy45 Dyy46 Dyy47 Dyy48 Dyy49 Dyy50 Dyy51 Dyy52, r
    This leaves out Dyy34 where yy=2000 to make yy=2000 the base year for the index. What I need to do is capture the coefficient for each Dyy, to then create the (β_k) variable to be used in a scatter plot for visualization and comparison with a different index.

    How would this be done? I apologize for the relatively basic question, I recognize it is probably a simple answer I just cannot seem to find any answers online.

    Thanks in advance,

    Josh

  • #2
    Why do it the hard way? Let's do it the easy way with factor-variable notation. Forget the Dyy variables.

    Code:
    reg lprice age age2 twnhome acres acres2 sfla rmbed bath bath2 dist dist2 ib2000.yy, r
    Now, I don't understand what your "index" is supposed to be. I don't get what H is. So let's say you were just trying to calculate 100*exp(beta_k) for each k between 1967 and 2018, except 2000:

    Code:
    forvalues y = 1967/2018 {
        if `y' != 2000 {
            display 100*exp(_b[`y'.yy])
        }
    }
    I know that's not actually what you want to do, but the code shows you how to access the regression coefficients in the virtual _b[] matrix. You can re-purpose that to your actual needs.

    Note: the code is not tested because you did not provide example data to test it on. So beware of unmatched braces, parens, quotes, etc., or other typos. But it gives you the gist of it.

    Do read -help fvvarlist- to learn about factor variable notation. Not only will it save you a lot of time, it also keeps you from making a lot of errors (typos, omissions, duplications). It's quick, easy, and foolproof.




    Comment


    • #3
      Thank you Clyde, that worked perfectly, and yes the notation was incorrect.

      I will be sure to include example data in the future, I am still a novice with STATA and with the forums here. Thank you for the recommendation, I had not used factor variable notation in the past and will be sure to look into it.

      Thank you!

      Comment

      Working...
      X