Announcement

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

  • Panel data: SUBGROUP ANALYSIS

    Hi everyone,

    I am working with panel data (60 coutries, 2010-2022) and want to analyze the impact of several independent variables on different dependent variables across country groups (e.g., developing vs. developed countries)

    Question 1: I am planning to assign each country to a fixed group based on its classification in a base year (or initial year) and keep it constant throughout the panel. Is this a common and recommended approach?

    How do most authors prefer fixed (time-invariant) classification, time-varying classification, or other methods?

    Question 2: I am thinking of splitting the dataset into two separate files (one for each group) and running regressions separately on each file. However, this seems time-consuming.

    I have read about using by or bysort in Stata. Does using the by: prefix (or bysort) produce equivalent results to running the same regressions on two separately saved datasets?

    Any references to good papers or best practices would be highly appreciated.

    Thank you in advance!

  • #2
    My answer to your 2nd question only:

    If reading the Stata documentation leaves you in doubt whether splitting the data in separate files and running your regression model with each file separately will actually yield the same results as using the prefix -by- (or -bysort-), you could experiment with both strategies. You also could run the regression model first using -if- to specify the respective group and subsequently run it with the prefix -by- and observe the results. Here an example of the latter:
    Code:
    cls 
    cap which fre           // user written program for frequency tables (SSC) 
    if _rc ssc install fre  // install if necessary 
     
    sysuse auto, clear 
    fre foreign 
     
    sum rep78 if foreign==0 
    return list             // show stored results 
    sum rep78 if foreign==1 
    return list             // show stored results 
    bys foreign: sum rep78 
    return list             // show stored results
    with the result
    Code:
    . cap which fre           // user written program for frequency tables (SSC)
    . if _rc ssc install fre  // install if necessary
    
    . sysuse auto, clear
    (1978 automobile data)
    
    . fre foreign
    
    foreign -- Car origin
    ----------------------------------------------------------------
                       |      Freq.    Percent      Valid       Cum.
    -------------------+--------------------------------------------
    Valid   0 Domestic |         52      70.27      70.27      70.27
            1 Foreign  |         22      29.73      29.73     100.00
            Total      |         74     100.00     100.00           
    ----------------------------------------------------------------
    
    . sum rep78 if foreign==0
    
        Variable |        Obs        Mean    Std. dev.       Min        Max
    -------------+---------------------------------------------------------
           rep78 |         48    3.020833     .837666          1          5
    
    . return list             // show stored results
    
    scalars:
                      r(N) =  48
                  r(sum_w) =  48
                   r(mean) =  3.020833333333333
                    r(Var) =  .7016843971631205
                     r(sd) =  .8376660415482535
                    r(min) =  1
                    r(max) =  5
                    r(sum) =  145
    
    . sum rep78 if foreign==1
    
        Variable |        Obs        Mean    Std. dev.       Min        Max
    -------------+---------------------------------------------------------
           rep78 |         21    4.285714    .7171372          3          5
    
    . return list             // show stored results
    
    scalars:
                      r(N) =  21
                  r(sum_w) =  21
                   r(mean) =  4.285714285714286
                    r(Var) =  .5142857142857143
                     r(sd) =  .7171371656006362
                    r(min) =  3
                    r(max) =  5
                    r(sum) =  90
    
    . bys foreign: sum rep78
    
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    -> foreign = Domestic
    
        Variable |        Obs        Mean    Std. dev.       Min        Max
    -------------+---------------------------------------------------------
           rep78 |         48    3.020833     .837666          1          5
    
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    -> foreign = Foreign
    
        Variable |        Obs        Mean    Std. dev.       Min        Max
    -------------+---------------------------------------------------------
           rep78 |         21    4.285714    .7171372          3          5
    
    
    . return list             // show stored results
    
    scalars:
                      r(N) =  21
                  r(sum_w) =  21
                   r(mean) =  4.285714285714286
                    r(Var) =  .5142857142857143
                     r(sd) =  .7171371656006362
                    r(min) =  3
                    r(max) =  5
                    r(sum) =  90
    Both strategies will produce the same results for -sum- and would also do for -regress- or other commands that allow the -by- prefix (as would splitting the dataset into different files with selecting the cases if foreign equal to 0 and foreign equal to 1).

    However, note that the stored results (or estimates) are only available for the last group defined by -by-. If using -by- or splitting the datasets would be more or less efficient in terms of execution time (except for the tasks of splitting the data, saving them, and using them), I would expect the differences to be small.

    For a more elaborate explanation of the use of -by- see Nick Cox's article "Speaking Stata: How to move step by: step".

    Comment


    • #3
      Add on:

      Note that results of splitting datasets (or analyzing data of a specific group using -if-) will not be identical when using the -svy- prefix command. See the option -subpop()- of the -svy- prefix command. But in this case you wouldn't use -by-, anyway.

      Comment


      • #4
        Question 1: that is a substantive decision. So it just depends on what you are studying and if it is reasonable to assume constant groupings (that makes your analysis and interpretation a lot easier) or time changing grouping.

        Question 2: Dirk gave you answers. It also depends on what you want to do with those models: Do you want to collect those in a table, or do you want to make graphs, or something else. In all those cases it is helpful if you store your results. I find that easiest in a loop:

        Code:
        . clear
        
        . sysuse nlsw88
        (NLSW, 1988 extract)
        
        . 
        . // because of the data I make groups of occupation
        . // instead of countries
        . 
        . gen byte oclass:class_lb = 1 if inlist(occupation, 1,2)
        (1,665 missing values generated)
        
        . replace oclass = 2 if inlist(occupation,3, 4,11,12)
        (846 real changes made)
        
        . replace oclass = 3 if inlist(occupation,5,6, 7, 8,9, 10,13)
        (810 real changes made)
        
        . label define class_lb 1 "higher service" ///
        >                       2 "lower service"  ///
        >                                       3 "manual"
        
        . 
        . collect clear                              
        
        . forvalues c = 1/3 {
          2.     reg wage grade i.race ttl_exp if oclass == `c'      
          3.         estimates store class_`c'
          4. }
        
              Source |       SS           df       MS      Number of obs   =       580
        -------------+----------------------------------   F(4, 575)       =     17.60
               Model |  3009.61262         4  752.403155   Prob > F        =    0.0000
            Residual |  24575.7177       575  42.7403786   R-squared       =    0.1091
        -------------+----------------------------------   Adj R-squared   =    0.1029
               Total |  27585.3303       579  47.6430575   Root MSE        =    6.5376
        
        ------------------------------------------------------------------------------
                wage | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
        -------------+----------------------------------------------------------------
               grade |   .7806312   .1189773     6.56   0.000     .5469481    1.014314
                     |
                race |
              Black  |  -.2156034   .7481523    -0.29   0.773    -1.685048    1.253841
              Other  |  -.1850825   2.096095    -0.09   0.930    -4.302018    3.931853
                     |
             ttl_exp |   .3510774   .0693494     5.06   0.000     .2148683    .4872865
               _cons |  -5.143983   1.952054    -2.64   0.009    -8.978009   -1.309958
        ------------------------------------------------------------------------------
        
              Source |       SS           df       MS      Number of obs   =       846
        -------------+----------------------------------   F(4, 841)       =     12.18
               Model |  1429.90636         4  357.476591   Prob > F        =    0.0000
            Residual |  24680.6796       841  29.3468247   R-squared       =    0.0548
        -------------+----------------------------------   Adj R-squared   =    0.0503
               Total |  26110.5859       845  30.9001017   Root MSE        =    5.4173
        
        ------------------------------------------------------------------------------
                wage | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
        -------------+----------------------------------------------------------------
               grade |   .3788674   .1036278     3.66   0.000      .175468    .5822669
                     |
                race |
              Black  |   -.276188   .4502339    -0.61   0.540    -1.159902    .6075259
              Other  |   .8797768   1.935371     0.45   0.650    -2.918947      4.6785
                     |
             ttl_exp |   .2208659   .0404862     5.46   0.000        .1414    .3003317
               _cons |   -.229767   1.377118    -0.17   0.868    -2.932758    2.473224
        ------------------------------------------------------------------------------
        
              Source |       SS           df       MS      Number of obs   =       809
        -------------+----------------------------------   F(4, 804)       =     59.13
               Model |  2890.05145         4  722.512863   Prob > F        =    0.0000
            Residual |  9824.76124       804  12.2198523   R-squared       =    0.2273
        -------------+----------------------------------   Adj R-squared   =    0.2235
               Total |  12714.8127       808  15.7361543   Root MSE        =    3.4957
        
        ------------------------------------------------------------------------------
                wage | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
        -------------+----------------------------------------------------------------
               grade |   .4970085   .0436102    11.40   0.000     .4114052    .5826118
                     |
                race |
              Black  |  -.4187519    .263612    -1.59   0.113     -.936201    .0986972
              Other  |  -.4377351   1.256866    -0.35   0.728    -2.904862    2.029392
                     |
             ttl_exp |   .1566698   .0270054     5.80   0.000     .1036604    .2096792
               _cons |  -1.844632   .5963838    -3.09   0.002    -3.015285   -.6739784
        ------------------------------------------------------------------------------
        
        . 
        . etable , estimates( class_1 class_2 class_3) mstat(N) mstat(r2)
        
        -----------------------------------------------------
                                        wage    wage    wage 
        -----------------------------------------------------
        Current grade completed         0.781   0.379   0.497
                                      (0.119) (0.104) (0.044)
        Race                                                 
          Black                        -0.216  -0.276  -0.419
                                      (0.748) (0.450) (0.264)
          Other                        -0.185   0.880  -0.438
                                      (2.096) (1.935) (1.257)
        Total work experience (years)   0.351   0.221   0.157
                                      (0.069) (0.040) (0.027)
        Intercept                      -5.144  -0.230  -1.845
                                      (1.952) (1.377) (0.596)
        Number of observations            580     846     809
        R-squared                        0.11    0.05    0.23
        -----------------------------------------------------
        
        .                         
        . collect label levels etable_depvar 1 "higher service" 2 "lower service" 3 "manual", modify
        
        . 
        . collect preview
        
        ------------------------------------------------------------------
                                      higher service lower service  manual
        ------------------------------------------------------------------
        Current grade completed                0.781         0.379   0.497
                                             (0.119)       (0.104) (0.044)
        Race                                                              
          Black                               -0.216        -0.276  -0.419
                                             (0.748)       (0.450) (0.264)
          Other                               -0.185         0.880  -0.438
                                             (2.096)       (1.935) (1.257)
        Total work experience (years)          0.351         0.221   0.157
                                             (0.069)       (0.040) (0.027)
        Intercept                             -5.144        -0.230  -1.845
                                             (1.952)       (1.377) (0.596)
        Number of observations                   580           846     809
        R-squared                               0.11          0.05    0.23
        ------------------------------------------------------------------
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          Man:
          Q1) assuming you want to go -xtreg,fe-, please note that, because of demeaning, no coefficient for time-invariant predictors will be calculated.
          The -fe- estimator is always consistent even when the -re- estimator is preferable (but is inefficient when -re- is the way to go);
          Q2) what is the expected payoff from running two different regressions?
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment

          Working...
          X