Announcement

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

  • Saving F-statistics in a for loop

    Hello,

    I am working on a project which requires testing the significance of a subset of of my regressors using progressively smaller time periods of panel data as follows:

    forvalues i=1997/2016{
    eststo clear
    xi: reg Y i.X1 i.state i.year i.month if year>=`i'
    eststo Y
    testparm _X1__2-_X1__132
    }

    I want to save the F-statistic from each test of X1 (the test for 1991 -2016, 1992 - 2016, and so on). The end goal is to produce a figure which shows how the F-stat for joint significance of the ~130 X1 variables changes over the smaller periods of data.

    Any help would be much appreciated!

  • #2
    I wonder what version of Stata you are working with. The code looks like it was written for a very old version. If you are using the current version (which is 17, and you are supposed to tell us what version you are using if it is not the current one), you can do this as:

    Code:
    frame create fstats int i float F ndf ddf
    forvalues i = 1997/2016 {
        reg Y i.X1 i.state i.year i.month if year >= `i'
        testparm i.X1
        frame post fstats (`i') (r(F)) (r(df)) (r(df_r))
    }
    frame change fstats
    graph twoway line F year, sort
    I have omitted all of the -eststo- code because it does not seem relevant to your stated goals. I have eliminated the use of the effectively obsolete -xi:- prefix, relying instead on factor-variable notation. I have stored, along with the F statistic, its numerator and denominator degrees of freedom. While they aren't needed for your immediate purpose, it seems to me it is hard to make much sense of the F statistic without the degrees of freedom for context.

    Comment


    • #3
      Hello,

      Thank you for the response! I'm using an updated version of Stata but my training on a few things might be outdated. I'll give this a shot!

      Dan

      Comment


      • #4
        I just noticed, the first line in the code should be
        Code:
        frame create fstats int year float F ndf ddf

        Comment

        Working...
        X