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:
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:
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:
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:
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)
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);
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
Comment