Announcement

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

  • How to regress on multiple constants in panel data and perform Chow-Test?

    Dear Statalists,

    I also posted this question on researchgate.net but just figured it might be better placed in a Stata-Forum since it is a Stata-specific question.

    I have a cyclical time series y_t for two groups. By splitting the cycles into fixed phases I compare the average value per phase between those groups and thus try to compare the cycle pattern phase-wise. For this I introduce dummy variables per phase and regress on a constant to obtain the average over all cycles for each phase. I then perform Chow-Test (manually) as described in the Stata-FAQ to compare the estimated averages between both groups.

    For the following example data (see bottom), I simplify all cycles to be of length of one year and split each cycle into 4 phases, so that we can use the quarters as phases.
    I tried to apply the examples given in the Stata-FAQ and other Stata-links as linked in the Example-Code, yet the simplification to regression on a constant without further independent variables somehow leaves following questions open:
    1. Do I need to regress each phase separately or can I pool them somehow together in Stata? The Stata-FAQ explains how to regress for both groups at the same time, but not on how this can be performed for multiple constants to regress on (in my case the phases).
    2. When regressing the constant term per phase, do I need to prune the panel to data only related to the phase being regressed or can I use the entire dataset per group (as implemented now)?
    3. How do I perform Chow-Test here using the command test instead of manually calculating the Chow-Test statistic?
    Any help is highly appreciated.

    Cheers,
    Jonathan




    Code:
    * Generate Example Data
    *  date:    ranges from 0 to 11 - interpreted as Quarterly Dateformat this ranges from 1960q1 to 1962q4
    *  group:  indicates what group (1 or 2) the data belongs to
    * value:   imaginary data, which is identical for both groups for q1, q2 and q4 but (in average) slighty different for q3
    input date group value
    * Group 1
    0  1 1
    1  1 0.5
    2  1 -0.5
    3  1 -1
    4  1 1
    5  1 0.5
    6  1 -0.5
    7  1 -1
    8  1 1
    9  1 0.5
    10 1 -0.5
    11 1 -1
    * Group 2
    0  2 1
    1  2 0.5
    2  2 -0.5
    3  2 -1
    4  2 1
    5  2 0.5
    6  2 -0.5
    7  2 -1
    8  2 1
    9  2 0.5
    10 2 -0.3
    11 2 -1
    end
    
    * Pre-Process Time
    format %tq date
    xtset group date
    gen quarter = quarter(dofq(date))
    gen year = year(dofq(date))
    
    
    * Analyse Example Data:
    *    Phase 1, 2 and 4 are identical for all years and both groups
    *    Phase 3 differs for Group 2 for the third year (1962), thus the average for phase 3 will differ as well
    line value quarter if group == 1 & year == 1960 || line value quarter if group == 2 & year == 1960, lpattern(dash)
    line value quarter if group == 1 & year == 1961 || line value quarter if group == 2 & year == 1961, lpattern(dash)
    line value quarter if group == 1 & year == 1962 || line value quarter if group == 2 & year == 1962, lpattern(dash)
    
    * Perform Chow-Test (for Quarter/Phase 3)
    * See: http://www.stata.com/support/faqs/statistics/computing-chow-statistic/
    * Create Dummy Variable (See: http://stats.idre.ucla.edu/stata/faq/how-can-i-create-dummy-variables-in-stata/)
    tabulate quarter, generate(phase)
    * Run the separate regressions
    regress value phase3 if group==1, vce(robust)
    scalar ess_1 = e(rss)
    scalar N_1   = e(N)
    regress value phase3 if group==2, vce(robust)
    scalar ess_2 = e(rss)
    scalar N_2   = e(N)
    * Run the combined regression
    regress value phase3, vce(robust)
    scalar ess_c = e(rss)
    scalar k     = 3
    
    scalar F_chow_num = (ess_c -(ess_1+ess_2))/3
    scalar F_chow_den = (ess_1+ess_2)/(N_1+N_2-2*k)
    scalar F_chow     = F_chow_num / F_chow_den
    
    display F_chow

  • #2
    See http://www.stata.com/support/faqs/st...how-statistic/

    Comment


    • #3
      Hello Clyde,

      thanks for the link. That's actually the approach I follow and link to in my example. I read the FAQ and also the Documentation to contrast (especially the Chow test example) again and think the following should be the apropriate approach:

      Code:
      gen g2 = (group == 2)
      regress value i.quarter##i.g2, vce(robust)
      contrast g2 g2#i.quarter, overall
      Comparing the results I obtain with my previous ones I conclude as answers to my own questions:
      1. Pooling in this case might be done using full factorial of two indicator variables (see above: i.quarter##i.g2).
      2. If I compare my results I guess this should not be done. I am not sure on this statement. I do get very different results for the manually Chow Test Statistics and the results of command contrast. I noticed, that I set my DoF wrong in my code above. I guess it should be k=2, not k=3. Still I am not confident with the test results contrast returns in the example above. Any ideas on this one?
      3. Well I guess the contrast command is ideal here.
      Thanks allready!

      Comment


      • #4
        Hello everyone,

        so I did some further reading beyond the FAQ and found following helpful:I found the hint to "forget about Chow-Test" very (!) useful. Additionally, using the example in the STATA-FAQ (careful, there are two different one son Chow-Test) I adopted my example code above and came to following conclusions for my example:
        1. Yes, regressing on all phases simultaneously can be done. I manually generated group-specific phase-dummy variables instead using indicator variables. So for 4 phase-dummy-variables and two groups I now have 8 dummy variables.
        2. With #1 above I automatically can answer #2: No, all data can be taken into account when regressing.
        3. I want to compare each phase separately between the two groups. For this I use the flexibility the command test brings along.
        With the above, hopefully now correct, insights, my example now looks as following (Hint: My real data is heteroskedastic, I thus use regression with Newey-West standard errors and allow for certain lag order of autocorrelation. Since my data is split into two groups, the Time-Variable has repeating values, which throws errors with the command newey. Instead of introducing a new dummy-time-variable I instead use the command newey2, which can handle this and gives identical results as for a dummy time variable. If needed, newey2 can be installed using ssc install newey2.):

        Code:
        cls
        clear
        
        * Generate some artificial Data
        set obs 120
        set seed 1234
        generate x = 1
        generate y = 100*x + 20 * rnormal()
        generate t = _n
        generate group = 1
        save one, replace
        
        clear
        set obs 40
        generate x = 1
        generate y = 100*x + 15 * uniform()
        generate group = 2
        generate t = _n
        save two, replace 
        
        use one, clear
        append using two
        save combined, replace
        
        
        * Assume TimeFormat is quarterly and split into quarters
        format %tq t
        gen quarter = quarter(dofq(t))
        gen year = year(dofq(t))
        
        * Generate Dummy Variables for all Quarters/Phases
        tabulate quarter, generate(phase)
        
        gen g1       = (group==1)
        gen g2       = (group==2)
        gen phase1g1 = phase1*g1
        gen phase2g1 = phase2*g1
        gen phase3g1 = phase3*g1
        gen phase4g1 = phase4*g1
        gen phase1g2 = phase1*g2
        gen phase2g2 = phase2*g2
        gen phase3g2 = phase3*g2
        gen phase4g2 = phase4*g2
        
        xtset group t
        newey2 y phase1g1 phase2g1 phase3g1 phase4g1 phase1g2 phase2g2 phase3g2 phase4g2, lag(6) noconstant
        
        * Test for identical coefficients in one phase for thw two groups
        test phase1g1 = phase1g2

        Comment

        Working...
        X