Announcement

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

  • Saving F stat after Regression

    Hi All,


    I have data that resembles the following:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(y x year)
     23   1 1999
    123   2 1999
    123 123 1999
      2 123 1999
    123 123 2000
    123  23 2000
    123 123 2000
      2   3 2000
     21  12 2000
    end

    In the above, I perform regressions of y on x year-on-year, and wish to save the point estimates as well as the F-statistic. At present, I use the following code:

    Code:
    gen IV=.
    g F=.
    levelsof year, local(year)
    foreach i of local year {
    regress y x  if year == `i'  
    gen temp2=_b[x]
    replace IV=temp2 if  year == `i'
    g temp3=r(F)
    replace F=temp4 if year==`i'
    drop temp2
    drop temp3
    }
    Although the coefficient vector is generated appropriately, I get a blank vector for the F-statistics. Any help on this is much appreciated.

    Best,
    CS

  • #2
    Chinmay:
    this should work:
    Code:
    use http://www.stata-press.com/data/r15/nlswork
    gen IV=.
    g F=.
    levelsof year, local(year)
    foreach i of local year {
    regress ln_wage age  if year == `i'
    gen temp2=_b[age]
    replace IV=temp2 if  year == `i'
    g temp3=e(F)
    replace F=temp3 if year==`i'
    drop temp2
    drop temp3
    }
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thanks a lot Carlo Lazzaro !

      Comment

      Working...
      X