Announcement

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

  • Clustering in Fixed Effect Regression with Reshaped Panel Data

    Hi,

    I am working on a fixed effects regression analysis using a panel dataset with monthly data on location units and price changes, influenced by variables that vary across different countries. My dataset initially had the country-level variable in a wide format, with each country represented as a separate column such that I ran this regression:

    Code:
    foreach country in africa middleeast  {
        xtreg dspread_`country' ldspread_`country' L(1/12).unct_`country', fe robust
    }

    To improve my analysis I would like to do country year clustering to account for location cross time fixed effects and the cross sectional correlation and time series dependence. The regression I am trying to run would look like this:
    Code:
    xtreg dspread_* ldspread_* L(1/12).unct_*, fe vce(cluster country yearvar)
    Therefore, I reshaped the data into a long format to incorporate the country variable more effectively. However, post-reshaping, each unique location-time combination (ward_num and month) now corresponds to multiple rows due to the added country variable. In other words for each location month, there is a row for "africa" and one for "middleeast". This causes issues when trying to set my panel data for fixed effects regression:
    reshape long spread_ wui_ dspread_ ldspread_ dwui_ unct_, i(ward_num monthlyvar) j(country) string
    gen yearvar = year(dofm(monthlyvar))
    sort ward_num monthlyvar

    . xtset ward_num monthlyvar
    repeated time values within panel
    r(451);

    Could anyone suggest a workaround or alternative approach for this data structure issue? How can I effectively incorporate country-year clustering in this setup?

    Thank you in advance for your help and insights!


    The data looks like this after reshaping:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long ward_num float(monthlyvar yearvar) str14 country float(dspread_ ldspread_ unct_)
    1 660 2015 "africa" -.01273128 .014274824 0
    1 660 2015 "middleeast" -.017508611 .019569613 0
    1 661 2015 "africa" -.015691198 -.01273128 0
    1 661 2015 "middleeast" .03139296 -.017508611 0
    1 662 2015 "africa" .08255005 -.015691198 0
    1 662 2015 "middleeast" -.034069523 .03139296 0
    1 663 2015 "africa" -.05759017 .08255005 0
    1 663 2015 "middleeast" .016335353 -.034069523 0
    1 664 2015 "africa" .035960466 -.05759017 0
    1 664 2015 "middleeast" -.008077189 .016335353 0
    1 665 2015 "africa" .016428001 .035960466 0
    1 665 2015 "middleeast" -.031927027 -.008077189 0
    1 666 2015 "africa" -.0044620577 .016428001 0
    1 666 2015 "middleeast" -.008583674 -.031927027 0
    1 667 2015 "africa" -.0003889892 -.0044620577 0
    1 667 2015 "middleeast" -.02492235 -.008583674 0
    1 668 2015 "africa" -.024398034 -.0003889892 0
    1 668 2015 "middleeast" .05400065 -.02492235 0
    1 669 2015 "africa" .02820484 -.024398034 1
    1 669 2015 "middleeast" -.001000002 .05400065 0
    1 670 2015 "africa" -.01822365 .02820484 0
    1 670 2015 "middleeast" -.008926474 -.001000002 0
    1 671 2015 "africa" .0039288327 -.01822365 0
    1 671 2015 "middleeast" .01623942 -.008926474 0
    1 672 2016 "africa" -.002127517 .0039288327 0
    1 672 2016 "middleeast" -.01431036 .01623942 0
    1 673 2016 "africa" .04208383 -.002127517 0
    1 673 2016 "middleeast" .0015582517 -.01431036 0
    1 674 2016 "africa" -.01246523 .04208383 0
    1 674 2016 "middleeast" -.04449745 .0015582517 0
    1 675 2016 "africa" .05236107 -.01246523 0
    1 675 2016 "middleeast" .01941245 -.04449745 0
    1 676 2016 "africa" -.026499826 .05236107 0
    1 676 2016 "middleeast" -.01979743 .01941245 0
    1 677 2016 "africa" -.02334593 -.026499826 0
    1 677 2016 "middleeast" -.02490872 -.01979743 0
    1 678 2016 "africa" .015093558 -.02334593 1
    1 678 2016 "middleeast" -.03613212 -.02490872 1
    1 679 2016 "africa" -.011342783 .015093558 0
    1 679 2016 "middleeast" .025140826 -.03613212 0
    1 680 2016 "africa" .04714107 -.011342783 0
    1 680 2016 "middleeast" .033584423 .025140826 0
    1 681 2016 "africa" -.07134539 .04714107 0
    1 681 2016 "middleeast" -.011004753 .033584423 0
    1 682 2016 "africa" .05198849 -.07134539 0
    1 682 2016 "middleeast" .005849187 -.011004753 0
    1 683 2016 "africa" -.02892708 .05198849 1
    1 683 2016 "middleeast" .013701008 .005849187 0
    2 660 2015 "africa" -.01273128 .014274824 0
    2 660 2015 "middleeast" -.017508611 .019569613 0
    2 661 2015 "africa" -.015691198 -.01273128 0
    2 661 2015 "middleeast" .03139296 -.017508611 0
    2 662 2015 "africa" .08255005 -.015691198 0
    2 662 2015 "middleeast" -.034069523 .03139296 0
    2 663 2015 "africa" -.05759017 .08255005 0
    2 663 2015 "middleeast" .016335353 -.034069523 0
    2 664 2015 "africa" .035960466 -.05759017 0
    2 664 2015 "middleeast" -.008077189 .016335353 0
    2 665 2015 "africa" .016428001 .035960466 0
    2 665 2015 "middleeast" -.031927027 -.008077189 0
    2 666 2015 "africa" -.0044620577 .016428001 0
    2 666 2015 "middleeast" -.008583674 -.031927027 0
    2 667 2015 "africa" -.0003889892 -.0044620577 0
    2 667 2015 "middleeast" -.02492235 -.008583674 0
    2 668 2015 "africa" -.024398034 -.0003889892 0
    2 668 2015 "middleeast" .05400065 -.02492235 0
    2 669 2015 "africa" .02820484 -.024398034 1
    2 669 2015 "middleeast" -.001000002 .05400065 0
    2 670 2015 "africa" -.01822365 .02820484 0
    2 670 2015 "middleeast" -.008926474 -.001000002 0
    2 671 2015 "africa" .0039288327 -.01822365 0
    2 671 2015 "middleeast" .01623942 -.008926474 0
    2 672 2016 "africa" -.002127517 .0039288327 0
    2 672 2016 "middleeast" -.01431036 .01623942 0
    2 673 2016 "africa" .04208383 -.002127517 0
    2 673 2016 "middleeast" .0015582517 -.01431036 0
    2 674 2016 "africa" -.01246523 .04208383 0
    2 674 2016 "middleeast" -.04449745 .0015582517 0
    2 675 2016 "africa" .05236107 -.01246523 0
    2 675 2016 "middleeast" .01941245 -.04449745 0
    2 676 2016 "africa" -.026499826 .05236107 0
    2 676 2016 "middleeast" -.01979743 .01941245 0
    2 677 2016 "africa" -.02334593 -.026499826 0
    2 677 2016 "middleeast" -.02490872 -.01979743 0
    2 678 2016 "africa" .015093558 -.02334593 1
    2 678 2016 "middleeast" -.03613212 -.02490872 1
    2 679 2016 "africa" -.011342783 .015093558 0
    2 679 2016 "middleeast" .025140826 -.03613212 0
    2 680 2016 "africa" .04714107 -.011342783 0
    2 680 2016 "middleeast" .033584423 .025140826 0
    2 681 2016 "africa" -.07134539 .04714107 0
    2 681 2016 "middleeast" -.011004753 .033584423 0
    2 682 2016 "africa" .05198849 -.07134539 0
    2 682 2016 "middleeast" .005849187 -.011004753 0
    2 683 2016 "africa" -.02892708 .05198849 1
    2 683 2016 "middleeast" .013701008 .005849187 0
    3 660 2015 "africa" -.01273128 .014274824 0
    3 660 2015 "middleeast" -.017508611 .019569613 0
    3 661 2015 "africa" -.015691198 -.01273128 0
    3 661 2015 "middleeast" .03139296 -.017508611 0
    end
    format %tm monthlyvar
    label values ward_num ward_num
    label def ward_num 1 "E05009317", modify
    label def ward_num 2 "E05009318", modify
    label def ward_num 3 "E05009319", modify



  • #2
    Forgot to ask whether this would also work in this context?
    Code:
    reghdfe dspread_* ldspread_* L(1/12).unct_*, absorb(ward_num monthlyvar) vce(cluster country yearvar)
    This command produced warnings about the VCV matrix being non-positive semi-definite and the necessity of an adjustment. Additionally, I get no F-statistic.

    . reghdfe dspread_* ldspread_* L(1/12).unct_*, absorb(ward_num monthlyvar) vce(cluster country yearvar)
    (MWFE estimator converged in 5 iterations)
    note: L.unct_ is probably collinear with the fixed effects (all partialled-out values are close to zero; tol = 1.0e-09)
    Warning: VCV matrix was non-positive semi-definite; adjustment from Cameron, Gelbach & Miller applied.
    warning: missing F statistic; dropped variables due to collinearity or too few clusters

    HDFE Linear regression Number of obs = 1,033,620
    Absorbing 2 HDFE groups F( 12, 9) = .
    Statistics robust to heteroskedasticity Prob > F = .
    R-squared = 0.3939
    Adj R-squared = 0.3935
    Number of clusters (country) = 14 Within R-sq. = 0.2108
    Number of clusters (yearvar) = 10 Root MSE = 0.0286

    (Std. err. adjusted for 10 clusters in country yearvar)

    Comment

    Working...
    X