Hello all,
Can you help me how to test difference in means across groups in panel data? After reading online, I found two options: (1) running mixed effect regression and then test the parameter; (2) collapse the data (to remove the panel) and then do one way anova test. Here is the data sample and result so far:
This is the result by using mixed effect:
And this is by using oneway Anova:
My goal is to compare group 1 vs 3, so it seems the Anova method answered this by testing 3 vs 1 (p-value 0.334). Or should I just simply look at the coefficient and significance of
(p-value 0.098) in the mixed effect regression above? Thank you for your help.
Best,
Abdan
Can you help me how to test difference in means across groups in panel data? After reading online, I found two options: (1) running mixed effect regression and then test the parameter; (2) collapse the data (to remove the panel) and then do one way anova test. Here is the data sample and result so far:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str24 countryname int year float value byte group long ID "Albania" 2018 9.621069 2 1 "Albania" 2019 9.562582 2 1 "Albania" 2020 9.668357 2 1 "Albania" 2021 9.583389 2 1 "Albania" 2022 9.226106 2 1 "Algeria" 2018 1.134864 3 2 "Algeria" 2019 1.039727 3 2 "Algeria" 2020 1.166164 3 2 "Algeria" 2021 1.096307 3 2 "Algeria" 2022 .8507636 3 2 "Argentina" 2018 .0995468 2 3 "Argentina" 2019 .1253808 2 3 "Argentina" 2020 .1680119 2 3 "Argentina" 2021 .1846933 2 3 "Argentina" 2022 .2008211 2 3 "Armenia" 2018 11.9427 2 4 "Armenia" 2019 11.21892 2 4 "Armenia" 2020 10.49706 2 4 "Armenia" 2021 11.21718 2 4 "Armenia" 2022 10.42774 2 4 "Azerbaijan" 2018 2.601838 2 5 "Azerbaijan" 2019 2.646993 2 5 "Azerbaijan" 2020 3.286457 2 5 "Azerbaijan" 2021 2.784541 2 5 "Azerbaijan" 2022 5.017754 2 5 "Bahamas, The" 2018 0 1 6 "Bahamas, The" 2019 0 1 6 "Bahamas, The" 2020 .5208385 1 6 "Bahamas, The" 2021 .4601183 1 6 "Bahamas, The" 2022 .4488347 1 6 "Barbados" 2018 1.666766 1 7 "Barbados" 2019 1.594726 1 7 "Barbados" 2020 1.797415 1 7 "Barbados" 2021 1.730127 1 7 "Barbados" 2022 1.494327 1 7 "Burundi" 2018 1.811973 2 8 "Burundi" 2019 1.875734 2 8 "Burundi" 2020 1.823942 2 8 "Burundi" 2021 1.741071 2 8 "Burundi" 2022 1.447519 2 8 "Central African Republic" 2018 0 1 9 "Central African Republic" 2019 0 1 9 "Central African Republic" 2020 0 1 9 "Central African Republic" 2021 0 1 9 "Central African Republic" 2022 0 1 9 "China" 2018 .1749246 3 10 "China" 2019 .1281117 3 10 "China" 2020 .128517 3 10 "China" 2021 .1261466 3 10 "China" 2022 .1453294 3 10 "Comoros" 2018 14.52057 1 11 "Comoros" 2019 14.10411 1 11 "Comoros" 2020 18.50192 1 11 "Comoros" 2021 22.21997 1 11 "Comoros" 2022 22.68288 1 11 "Egypt, Arab Rep" 2018 9.716986 1 12 "Egypt, Arab Rep" 2019 8.403885 1 12 "Egypt, Arab Rep" 2020 7.712747 1 12 "Egypt, Arab Rep" 2021 7.414432 1 12 "Egypt, Arab Rep" 2022 5.942934 1 12 "Gabon" 2018 .1094308 3 13 "Gabon" 2019 .1093848 3 13 "Gabon" 2020 .120526 3 13 "Gabon" 2021 .0912953 3 13 "Gabon" 2022 .0875962 3 13 "Mauritania" 2018 .8080745 3 14 "Mauritania" 2019 .8164766 3 14 "Mauritania" 2020 2.041765 3 14 "Mauritania" 2021 .142859 3 14 "Mauritania" 2022 1.117382 3 14 "Seychelles" 2018 1.430288 3 15 "Seychelles" 2019 1.437503 3 15 "Seychelles" 2020 .8432241 3 15 "Seychelles" 2021 .7392818 3 15 "Seychelles" 2022 .632084 3 15 end label values ID ID label def ID 1 "Albania", modify label def ID 2 "Algeria", modify label def ID 3 "Argentina", modify label def ID 4 "Armenia", modify label def ID 5 "Azerbaijan", modify label def ID 6 "Bahamas, The", modify label def ID 7 "Barbados", modify label def ID 8 "Burundi", modify label def ID 9 "Central African Republic", modify label def ID 10 "China", modify label def ID 11 "Comoros", modify label def ID 12 "Egypt, Arab Rep", modify label def ID 13 "Gabon", modify label def ID 14 "Mauritania", modify label def ID 15 "Seychelles", modify
This is the result by using mixed effect:
Code:
mixed value i.group || ID: // Mixed effect model Performing EM optimization ... Performing gradient-based optimization: Iteration 0: Log likelihood = -151.58532 Iteration 1: Log likelihood = -151.58532 Computing standard errors ... Mixed-effects ML regression Number of obs = 75 Group variable: ID Number of groups = 15 Obs per group: min = 5 avg = 5.0 max = 5 Wald chi2(2) = 3.33 Log likelihood = -151.58532 Prob > chi2 = 0.1894 ------------------------------------------------------------------------------ value | Coefficient Std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- group | 2 | -.4860883 3.008294 -0.16 0.872 -6.382236 5.410059 3 | -4.976622 3.008294 -1.65 0.098 -10.87277 .919525 | _cons | 5.637344 2.127185 2.65 0.008 1.468138 9.806549 ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Random-effects parameters | Estimate Std. err. [95% conf. interval] -----------------------------+------------------------------------------------ ID: Identity | var(_cons) | 22.34822 8.261486 10.82876 46.12192 -----------------------------+------------------------------------------------ var(Residual) | 1.381789 .252279 .9661273 1.976283 ------------------------------------------------------------------------------ LR test vs. linear model: chibar2(01) = 147.18 Prob >= chibar2 = 0.0000 . testparm i.group ( 1) [value]2.group = 0 ( 2) [value]3.group = 0 chi2( 2) = 3.33 Prob > chi2 = 0.1894
And this is by using oneway Anova:
Code:
collapse (mean) value, by(countryname group) . oneway value group, tabulate | Summary of (mean) value group | Mean Std. dev. Freq. ------------+------------------------------------ 1 | 5.6373434 7.8125257 5 2 | 5.1512553 4.8542716 5 3 | .66072102 .49250825 5 ------------+------------------------------------ Total | 3.8164399 5.4422174 15 Analysis of variance Source SS df MS F Prob > F ------------------------------------------------------------------------ Between groups 75.2799162 2 37.6399581 1.33 0.3006 Within groups 339.368301 12 28.2806917 ------------------------------------------------------------------------ Total 414.648217 14 29.6177298 Bartlett's equal-variances test: chi2(2) = 15.0187 Prob>chi2 = 0.001 . pwmean value, over(group) mcompare(tukey) effects Pairwise comparisons of means with equal variances Over: group --------------------------- | Number of | comparisons -------------+------------- group | 3 --------------------------- ------------------------------------------------------------------------------ | Tukey Tukey value | Contrast Std. err. t P>|t| [95% conf. interval] -------------+---------------------------------------------------------------- group | 2 vs 1 | -.486088 3.363373 -0.14 0.989 -9.459108 8.486932 3 vs 1 | -4.976622 3.363373 -1.48 0.334 -13.94964 3.996398 3 vs 2 | -4.490534 3.363373 -1.34 0.404 -13.46355 4.482486 ------------------------------------------------------------------------------
My goal is to compare group 1 vs 3, so it seems the Anova method answered this by testing 3 vs 1 (p-value 0.334). Or should I just simply look at the coefficient and significance of
Code:
[value]3.group
Best,
Abdan
Comment