Announcement

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

  • Get predicted value using the coefficient

    Hi, I have problem to calculate the predicted value of my variable, cashtoasset, for each observation. I use panel data with gvkey (cross sectional unit) and year (time unit). I use this model to calculate the predicted value for cashtoasset but i fail a lot when i use the loop function:

    reg cashtoasset size markettobook cashflow ncworkingcapital bookleverage dividend acquisition


    this is the problem i mean:

    xtset gvkey year

    Panel variable: gvkey (unbalanced)
    Time variable: year, 1999 to 2022, but with gaps
    Delta: 1 unit


    . egen id=group(gvkey)

    . gen predicted_cashtoasset=.
    (6,302 missing values generated)

    . qui sum id, meanonly

    . local N= r(N)

    . forvalues i=1(1)`N' {
    reg cashtoasset size markettobook cashflow ncworkingcapital bookleverage dividend acquisition if id==`i'
    predict px if id==`i'
    replace predicted_cashtoasset = px if id==`i'
    drop px
    }
    no observations
    r(2000);

    Do anyone know how calculate the predicted value ? Thank you
    Attached Files
    Last edited by Intan Salsabila Firman; 20 Jul 2023, 17:18.

  • #2
    Intan:
    the issue seems to rest on the evidence that, for your first -gwkey- (panel identifier) , the variable -ncworkingcapital- is totally missing.
    Therefore, -forval- (provided that a loop is necessary for what you're after) cannot move on and returns the error message.
    That said, why, having a penel dataset, you -xtset- your data and then went -regress- instead of -xtreg-?
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Ah thank you so much for reminding me about the number of missing observation of my variables and using xtreg. Because i saw it somewhere in the forum they suggest using reg for panel data in looping function instead of xtreg. I'm gonna change and try it once again.

      Comment

      Working...
      X