Announcement

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

  • suest alternative for panel data

    Hi,

    I have a panel GDP data for over 200 countries for the years 1990 to 2018, which I am reducing to 6 different sub-samples. I am estimating the effect of 9 year dummies in each of these subsamples.

    I am attempting to show my regression estimates using suest, so that I can then make a linear combination of these estimates using lincom, which will amount to a pooled average. However, I have noticed that suest doesnt allow for clustering by country in the original regressions, and requires me to cluster by country when I use suest. I suspect this is not the equivalent. I was wondering if there is an alternative way to combine these estimates so that I can obtain the pooled average over the 6 sub-samples.

    Additionally, I would like to weight the linear combination by the standard error of the regression estimates. I am not aware how to do this without entering the values manually.

    The ** indicate the clustering I believe is necessary but am stopped from doing by suest.

    Part of my code is shown below

    Code:
    *US 
    replace subsamp = 6 if inlist(Country, 207, 41,27,134)
    balancetable Host Population GDP OwnGDPGROWTH GDPCAP GDPCapGrowth using "Documents\Masters\Thesis\Data\Country Panel\Output\BalancingUS2.xls" if year<=1997 & subsamp ==6 , pvalues   ctitles(Non-Host, Host, Difference(p)) replace
    reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib27.Country if subsamp == 6 , **cluster(CountryName)**
    eststo US
    outreg2 using "Documents\Masters\Thesis\Data\Country Panel\Output\Regressions\PoolingSample2.xml" , append excel word dec(3) ctitle(USA) nocons keep(Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4) addtext(Country FE, Y, Year FE, Y) title(Countries: FB Pooling)
    
    
    suest Bra SA Ger SKJap Fra US , cluster(CountryName)
    
    *Sum- Pre 4 pooled
    lincom (([Bra_mean]Pre4) + ([SA_mean]Pre4) + ([Ger_mean]Pre4)  + ([SKJap_mean]Pre4) + ([Fra_mean]Pre4)  +([US_mean]Pre4)  )/ 6
    *Pre3 estimate .......

  • #2
    This has been addressed a number of times in the forum, including just yesterday.

    https://www.statalist.org/forums/for...-fixed-effects


    You do not need suest if a joint estimation is possible. The following illustrates:

    Code:
    webuse grunfeld, clear
    gen gr= company<=5
    reg invest mvalue kstock i.company if gr, robust
    reg invest mvalue kstock i.company if !gr, robust
    reg invest i.gr#(c.mvalue c.kstock i.company), robust
    All the coefficients in the individual regressions will be there in the joint regression and you can proceed with what you want.

    Code:
     reg invest mvalue kstock i.company if gr, robust
    
    Linear regression                               Number of obs     =        100
                                                    F(6, 93)          =     143.29
                                                    Prob > F          =     0.0000
                                                    R-squared         =     0.9309
                                                    Root MSE          =     71.914
    
    ------------------------------------------------------------------------------
                 |               Robust
          invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          mvalue |   .1149211   .0204048     5.63   0.000     .0744013    .1554409
          kstock |   .3211845   .0423492     7.58   0.000     .2370873    .4052817
                 |
         company |
              2  |   187.4654   48.18549     3.89   0.000     91.77855    283.1522
              3  |  -151.0369   46.92387    -3.22   0.002    -244.2184   -57.85535
              4  |   65.81458   69.33213     0.95   0.345    -71.86528    203.4944
              5  |  -22.84211   77.54692    -0.29   0.769    -176.8349    131.1507
                 |
           _cons |  -98.29755   83.92478    -1.17   0.244    -264.9555    68.36042
    ------------------------------------------------------------------------------
    
    . reg invest mvalue kstock i.company if !gr, robust
    
    Linear regression                               Number of obs     =        100
                                                    F(6, 93)          =     222.37
                                                    Prob > F          =     0.0000
                                                    R-squared         =     0.8826
                                                    Root MSE          =     9.6546
    
    ------------------------------------------------------------------------------
                 |               Robust
          invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          mvalue |   .0826851   .0144297     5.73   0.000     .0540306    .1113397
          kstock |   .1144632   .0127318     8.99   0.000     .0891804     .139746
                 |
         company |
              7  |  -9.597125   5.183731    -1.85   0.067    -19.89099    .6967379
              8  |  -31.14303   5.717422    -5.45   0.000    -42.49669   -19.78936
              9  |  -28.55509   3.833705    -7.45   0.000    -36.16807   -20.94211
             10  |   -12.2173   4.463652    -2.74   0.007    -21.08123   -3.353376
                 |
           _cons |   8.757607    5.31171     1.65   0.103    -1.790396    19.30561
    ------------------------------------------------------------------------------
    
    . reg invest i.gr#(c.mvalue c.kstock i.company), robust
    note: 0b.gr#1b.company identifies no observations in the sample
    note: 0b.gr#2.company identifies no observations in the sample
    note: 0b.gr#3.company identifies no observations in the sample
    note: 0b.gr#4.company identifies no observations in the sample
    note: 0b.gr#5.company identifies no observations in the sample
    note: 1.gr#5.company omitted because of collinearity
    note: 1.gr#6.company identifies no observations in the sample
    note: 1.gr#7.company identifies no observations in the sample
    note: 1.gr#8.company identifies no observations in the sample
    note: 1.gr#9.company identifies no observations in the sample
    note: 1.gr#10.company identifies no observations in the sample
    
    Linear regression                               Number of obs     =        200
                                                    F(13, 186)        =     251.00
                                                    Prob > F          =     0.0000
                                                    R-squared         =     0.9477
                                                    Root MSE          =     51.307
    
    ------------------------------------------------------------------------------
                 |               Robust
          invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
     gr#c.mvalue |
              0  |   .0826851   .0144297     5.73   0.000     .0542182    .1111521
              1  |   .1149211   .0204048     5.63   0.000     .0746666    .1551756
                 |
     gr#c.kstock |
              0  |   .1144632   .0127318     8.99   0.000     .0893459    .1395805
              1  |   .3211845   .0423492     7.58   0.000     .2376379     .404731
                 |
      gr#company |
           0  1  |          0  (empty)
           0  2  |          0  (empty)
           0  3  |          0  (empty)
           0  4  |          0  (empty)
           0  5  |          0  (empty)
           0  6  |   129.8973   25.63084     5.07   0.000     79.33275    180.4618
           0  7  |   120.3001   25.36653     4.74   0.000     70.25705    170.3432
           0  8  |   98.75424   26.76852     3.69   0.000      45.9453    151.5632
           0  9  |   101.3422   25.57585     3.96   0.000     50.88615    151.7982
           0 10  |     117.68   25.09734     4.69   0.000     68.16793     167.192
           1  1  |   22.84211   77.54692     0.29   0.769    -130.1425    175.8267
           1  2  |   210.3075   44.93797     4.68   0.000     121.6538    298.9611
           1  3  |  -128.1948   39.75573    -3.22   0.001    -206.6249   -49.76464
           1  4  |   88.65668   22.66977     3.91   0.000     43.93376    133.3796
           1  5  |          0  (omitted)
           1  6  |          0  (empty)
           1  7  |          0  (empty)
           1  8  |          0  (empty)
           1  9  |          0  (empty)
           1 10  |          0  (empty)
                 |
           _cons |  -121.1397    25.0744    -4.83   0.000    -170.6064   -71.67288
    ------------------------------------------------------------------------------

    Comment


    • #3
      Thanks for your response, its very helpful.

      One issue that I am concerned about is that some countries are in more than one of the samples (treated as some and control in others). I thus have a problem assigning the correct sub-sample number. For example, the US is in both sample 1 and 6 and so I was doing the regressions sequentially so the US was able to be in both samples. There is probably an easy way round this that I am missing.

      Comment


      • #4
        You have overlapping samples and therefore, some data engineering is needed. Determine what countries are in two or more samples, e.g., by cross-tabbing the samples and then duplicate their observations, assigning new ids to the duplicate observations. Note that in Stata, factor variables need integer values, but there is no restriction on what these values should be beyond that they should not be the same as those that already exist in the data set. Here is an extension of my example in #2 to the case of overlapping samples. I assume that the sample-specific constant terms and dummy coefficients are not of use to you, but it is just a minor change to the code if you need them.



        Code:
        webuse grunfeld, clear
        
        *COUNTRIES WITH ID=4 & ID=5 ARE IN BOTH GROUPS
        gen gr= company<=5
        gen gr2= company>3
        
        *A CROSS TAB WILL SHOW YOU THIS
        bys company: gen firstob= _n==1
        tab gr gr2 if firstob
        list company if firstob & gr & gr2
        
        *SEPARATE REGRESSIONS
        regress invest mvalue kstock i.company if gr, robust
        regress invest mvalue kstock i.company if gr2, robust
        
        *NOW, KEEP ID=4 & ID=5 IN GROUP 1 AND DUPLICATE THESE FOR GROUP 2, ASSIGNING DIFFERENT IDs.
        *FOR FACTOR VARIABLES, THESE MUST BE INTEGERS. PRESERVE TO RESTORE ORIGINAL DATA SET LATER
        preserve
        keep if inlist(company, 4, 5)
        
        *HERE I USE ID=42 & ID=52 (FOR ID 4 IN GROUP 2 AND ID 5 IN GROUP 2)
        *THESE VALUES ARE ARBITRARY, BUT MORE IMPORTANTLY, NO COMPANIES IN THE DATA SET HAVE THESE IDs
        replace company =42 if company==4
        replace company = 52 if company==5
        
        *MAKE SURE NOT TO TAG THE FIRST GROUP AS WE WANT TO ASSIGN THESE EXCLUSIVELY TO THE SECOND
        replace gr=0
        
        *SAVE TO APPEND TO THE ORIGINAL
        tempfile toappend
        save `toappend'
        restore, preserve
        append using `toappend'
        
        *UNTAG OVERLAPPING COMPANIES FROM SECOND GROUP
        replace gr2=0 if inlist(company, 4, 5)
        
        *JOINT REGRESSION WITH OVERLAPPING SAMPLES
        regress invest c.gr#(c.mvalue c.kstock) c.gr2#(c.mvalue c.kstock) i.company, robust
        
        *RESTORE ORIGINAL DATA SET
        restore
        Results:

        Code:
        .
        . tab gr gr2 if firstob
        
                   |          gr2
                gr |         0          1 |     Total
        -----------+----------------------+----------
                 0 |         0          5 |         5
                 1 |         3          2 |         5
        -----------+----------------------+----------
             Total |         3          7 |        10
        
        .
        . list company if firstob & gr & gr2
        
             +---------+
             | company |
             |---------|
         61. |       4 |
         81. |       5 |
             +---------+

        Code:
        .
        . *SEPARATE REGRESSIONS
        
        .
        . regress invest mvalue kstock i.company if gr, robust
        
        Linear regression                               Number of obs     =        100
                                                        F(6, 93)          =     143.29
                                                        Prob > F          =     0.0000
                                                        R-squared         =     0.9309
                                                        Root MSE          =     71.914
        
        ------------------------------------------------------------------------------
                     |               Robust
              invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
              mvalue |   .1149211   .0204048     5.63   0.000     .0744013    .1554409
              kstock |   .3211845   .0423492     7.58   0.000     .2370873    .4052817
                     |
             company |
                  2  |   187.4654   48.18549     3.89   0.000     91.77855    283.1522
                  3  |  -151.0369   46.92387    -3.22   0.002    -244.2184   -57.85535
                  4  |   65.81458   69.33213     0.95   0.345    -71.86528    203.4944
                  5  |  -22.84211   77.54692    -0.29   0.769    -176.8349    131.1507
                     |
               _cons |  -98.29755   83.92478    -1.17   0.244    -264.9555    68.36042
        ------------------------------------------------------------------------------
        
        .
        . regress invest mvalue kstock i.company if gr2, robust
        
        Linear regression                               Number of obs     =        140
                                                        F(8, 131)         =     208.31
                                                        Prob > F          =     0.0000
                                                        R-squared         =     0.8234
                                                        Root MSE          =     14.475
        
        ------------------------------------------------------------------------------
                     |               Robust
              invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
              mvalue |   .0866886   .0142001     6.10   0.000     .0585973    .1147798
              kstock |   .1043643   .0210143     4.97   0.000     .0627931    .1459355
                     |
             company |
                  5  |  -22.44065   15.50077    -1.45   0.150    -53.10486     8.22357
                  6  |  -5.246596    7.54758    -0.70   0.488    -20.17751    9.684317
                  7  |  -11.63506   12.36293    -0.94   0.348    -36.09189    12.82177
                  8  |  -37.58296   6.347416    -5.92   0.000    -50.13966   -25.02625
                  9  |  -31.50123   10.38495    -3.03   0.003    -52.04514   -10.95732
                 10  |  -17.06009   9.057028    -1.88   0.062    -34.97706    .8568685
                     |
               _cons |   13.37647   9.831143     1.36   0.176    -6.071872    32.82482
        ------------------------------------------------------------------------------
        
        
        .
        . *JOINT REGRESSION WITH OVERLAPPING SAMPLES
        
        .
        . regress invest c.gr#(c.mvalue c.kstock) c.gr2#(c.mvalue c.kstock) i.company, ro
        > bust
        
        Linear regression                               Number of obs     =        240
                                                        F(15, 224)        =     238.90
                                                        Prob > F          =     0.0000
                                                        R-squared         =     0.9469
                                                        Root MSE          =     47.641
        
        --------------------------------------------------------------------------------
                       |               Robust
                invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        ---------------+----------------------------------------------------------------
         c.gr#c.mvalue |   .1149211   .0203683     5.64   0.000     .0747831    .1550591
                       |
         c.gr#c.kstock |   .3211845   .0422735     7.60   0.000     .2378798    .4044892
                       |
        c.gr2#c.mvalue |   .0866886   .0142182     6.10   0.000       .05867    .1147072
                       |
        c.gr2#c.kstock |   .1043643    .021041     4.96   0.000     .0629006     .145828
                       |
               company |
                    2  |   187.4654   48.09937     3.90   0.000     92.68024    282.2505
                    3  |  -151.0369   46.84001    -3.22   0.001    -243.3403   -58.73343
                    4  |   65.81458   69.20821     0.95   0.343    -70.56787     202.197
                    5  |  -22.84211   77.40832    -0.30   0.768    -175.3838    129.6996
                    6  |   106.4274   83.93204     1.27   0.206    -58.96997    271.8248
                    7  |    100.039   84.00387     1.19   0.235    -65.49998    265.5779
                    8  |   74.09107   84.24967     0.88   0.380    -91.93226    240.1144
                    9  |    80.1728   83.99729     0.95   0.341    -85.35319    245.6988
                   10  |   94.61393   83.78118     1.13   0.260    -70.48617     259.714
                   42  |    111.674   84.35112     1.32   0.187    -54.54922    277.8973
                   52  |   89.23338   84.44045     1.06   0.292     -77.1659    255.6327
                       |
                 _cons |  -98.29755   83.77478    -1.17   0.242    -263.3851    66.78994
        --------------------------------------------------------------------------------

        Comment


        • #5
          Hi,

          Thanks for your very response, it is very helpful.
          i have done this for 2 observations which were in 2 subsamples.
          - Country 134 in 2 and 5
          - country 207 in 1 and 6

          However, one observation (27) is in subsamples 1, 3 and 6 so i was wondering how to tackle this. I understand it is probably an iteration of the process you showed me but cant seem to work out the ordering .

          The code I have implemented for the first 2 (134 and 207 is below)

          Code:
          clear all
          use "C:\Users\nicha\OneDrive\Documents\Masters\Thesis\Data\Country Panel\Country Panel Merged Dataset with Format.dta" 
          gen subsamp1 = inlist(Country,43,11,100,93,207,27)
          gen subsamp2 = inlist(Country, 178, 59,134,114,198)
          gen subsamp3 = inlist(Country, 74, 206,27,134)
          gen subsamp4 = inlist(Country, 128,105,99)
          gen subsamp5 = inlist(Country, 69,134,189)
          gen subsamp6 = inlist(Country, 207, 41,27,134)
          
          *Cross tab to check countries that are in both subsamps  
          
          bys Country: gen firstob= _n==1
          tab subsamp1 subsamp2 if firstob
          list Country if firstob & subsamp1 & subsamp2
          * shows no obs in both subsamp1 and 2 - which countries are in both samples?
          tab subsamp1 subsamp6 if firstob
          list Country if firstob & subsamp1 & subsamp6
          *Countries 207 and 27 in both of these samples (1 and 6)
          tab subsamp1 subsamp3 if  firstob 
          list Country if firstob & subsamp1 & subsamp3
          
          *Country 27 is in 3 subsamples : 1,3,6 !!!!!!!!!!!!!!!!!!!1111
          tab subsamp2 subsamp5 if firstob
          list Country if firstob & subsamp2 & subsamp5
          *Country 134 is in both of these samples (2 and 5)
          
          *Separate regressions 
          *subsamp1 
          reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib27.Country if subsamp1 == 1 , cluster(CountryName)
          *subsamp2
          reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib27.Country if subsamp2 == 1 , cluster(CountryName)
          *subsamp3 
          reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib27.Country if subsamp3 == 1 ,cluster(CountryName)
          *subsamp4
          reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib27.Country if subsamp4 == 1 , cluster(CountryName)
          *subsamp5 
          reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib27.Country if subsamp5 == 1 , cluster(CountryName)
          *subsamp6 
          reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib27.Country if subsamp6 == 1 , cluster(CountryName)
          
          
          *issue: Country 27 is in 3 datasets - need to create 2 duplicates obs
          *NOW, KEEP ID=207 & ID=27 IN GROUP 1 AND DUPLICATE THESE FOR GROUP 6, ASSIGNING DIFFERENT IDs.
          *FOR FACTOR VARIABLES, THESE MUST BE INTEGERS. PRESERVE TO RESTORE ORIGINAL DATA SET LATER
          *first do for just 207 - 27 and 134 needed after 
          * 207 is in both 1 and 6. 
          * 134 is in both 2 and 5 
          * 27 need to create 2 observations , do twice - create obs 502 and 503 
          preserve
          keep if inlist(Country, 207 ,134)
          
          *HERE I USE ID=500 & ID=52 (FOR ID 207 IN GROUP 2 AND ID 27 IN GROUP 2)
          *THESE VALUES ARE ARBITRARY, BUT MORE IMPORTANTLY, NO COMPANIES IN THE DATA SET HAVE THESE IDs
          replace Country=500 if Country==207
          replace Country = 501 if Country == 134
          
          
          *MAKE SURE NOT TO TAG THE FIRST GROUP AS WE WANT TO ASSIGN THESE EXCLUSIVELY TO THE SECOND
          replace subsamp1 = 0
          replace subsamp2 =0 
          
          *SAVE TO APPEND TO THE ORIGINAL
          tempfile toappend
          save `toappend'
          restore, preserve
          append using `toappend'
          
          *UNTAG OVERLAPPING COMPANIES FROM SECOND GROUP
          replace subsamp6=0 if inlist(Country ,207)
          replace subsamp5 = 0 if inlist(Country, 134)
          
          *need to do this for 27 obs, which is in datasets 1,3 and 6
          
          *JOINT REGRESSION WITH OVERLAPPING SAMPLES
          set matsize 11000
          regress OwnGDPGROWTH  c.subsamp1#(c.Pre4 c.Pre3 c.Pre2 c.Pre1 c.t c.Post1 c.Post2 c.Post3 c.Post4 i.Country i.year) c.subsamp2#(c.Pre4 c.Pre3 c.Pre2 c.Pre1 c.t c.Post1 c.Post2 c.Post3 c.Post4 i.Country i.year) c.subsamp3#(c.Pre4 c.Pre3 c.Pre2 c.Pre1 c.t c.Post1 c.Post2 c.Post3 c.Post4 i.Country i.year)
          
          
          
          *RESTORE ORIGINAL DATA SET
          restore
          Thanks,

          Nic

          Comment


          • #6
            See
            Code:
            help expand
            for details on how to duplicate observations more than once. There is nothing much to add to #3, but I will provide an example with an overlap over 3 groups.

            Code:
            webuse grunfeld, clear
            gen gr1= inlist(company, 1,2,3,5)
            gen gr2= inlist(company, 2, 5, 6, 9, 10)
            gen gr3= inlist(company, 1, 4, 5, 7, 8)
            bys company: gen firstob=_n==1
            tab gr1 gr2
            list company if firstob& gr1& gr2
            tab gr1 gr3
            list company if firstob& gr1& gr3
            tab gr2 gr3
            list company if firstob& gr2& gr3
            
            *COMPANY 5 IS IN ALL 3 GROUPS, COMPANIES 1 & 2 IN 2 GROUPS
            
            *SEPARATE REGRESSIONS
            regress invest mvalue kstock i.company if gr1, robust
            regress invest mvalue kstock i.company if gr2, robust
            regress invest mvalue kstock i.company if gr3, robust
            
            *DUPLICATE OBSERVATIONS
            preserve
            *DUPLICATE ONCE
            keep if inlist(company, 1, 2)
            replace company=22 if company==2
            replace gr1=0 if company==22
            replace company=13 if company==1
            replace gr1=0 if company==13
            tempfile once
            save `once'
            restore, preserve
            
            *DUPLICATE TWICE
            keep if company==5
            expand 2, gen(x)
            replace company=52 if company==5 & !x
            replace gr1=0 if company==52
            replace gr3=0 if company==52
            replace company=53 if company==5 & x
            replace gr1=0 if company==53
            replace gr2=0 if company==53
            drop x
            tempfile twice
            save `twice'
            restore, preserve
            
            *APPEND DUPLICATES
            restore, preserve
            append using `once'
            append using `twice'
            
            *UNTAG OBSERVATIONS
            replace gr2=0 if company==2
            replace gr3=0 if company==1
            replace gr2=0 if company==5
            replace gr3=0 if company==5
            
            *JOINT REGRESSION
            regress invest c.gr1#(c.mvalue c.kstock) c.gr2#(c.mvalue c.kstock) c.gr3#(c.mvalue c.kstock) i.company, robust
            At the end, to check whether you have defined your groups correctly, you may try something like

            Code:
            list company gr* if firstob, clean
            Results:

            Code:
            . *SEPARATE REGRESSIONS
            
            .
            . regress invest mvalue kstock i.company if gr1, robust
            
            Linear regression                               Number of obs     =         80
                                                            F(5, 74)          =     126.48
                                                            Prob > F          =     0.0000
                                                            R-squared         =     0.9233
                                                            Root MSE          =     80.306
            
            ------------------------------------------------------------------------------
                         |               Robust
                  invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
                  mvalue |   .1158152   .0209275     5.53   0.000     .0741163    .1575142
                  kstock |   .3212348   .0433504     7.41   0.000     .2348572    .4076124
                         |
                 company |
                      2  |   189.5951   49.20851     3.85   0.000     91.54499    287.6452
                      3  |  -148.8852   48.05352    -3.10   0.003    -244.6339   -53.13645
                      5  |  -19.16596   79.59949    -0.24   0.810    -177.7714    139.4395
                         |
                   _cons |  -102.2052   86.07254    -1.19   0.239    -273.7084    69.29812
            ------------------------------------------------------------------------------
            
            .
            . regress invest mvalue kstock i.company if gr2, robust
            
            Linear regression                               Number of obs     =        100
                                                            F(6, 93)          =     181.67
                                                            Prob > F          =     0.0000
                                                            R-squared         =     0.9183
                                                            Root MSE          =     47.427
            
            ------------------------------------------------------------------------------
                         |               Robust
                  invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
                  mvalue |   .1490376    .036254     4.11   0.000     .0770443    .2210309
                  kstock |   .1416635    .057228     2.48   0.015       .02802     .255307
                         |
                 company |
                      5  |  -116.4808   77.18788    -1.51   0.135    -269.7606    36.79902
                      6  |   -96.7668   61.76035    -1.57   0.121    -219.4106    25.87702
                      9  |  -124.8677   68.41104    -1.83   0.071    -260.7185    10.98306
                     10  |  -83.15584    72.4894    -1.15   0.254    -227.1054    60.79375
                         |
                   _cons |   74.82875   74.89078     1.00   0.320     -73.8895     223.547
            ------------------------------------------------------------------------------
            
            .
            . regress invest mvalue kstock i.company if gr3, robust
            
            Linear regression                               Number of obs     =        100
                                                            F(6, 93)          =     128.09
                                                            Prob > F          =     0.0000
                                                            R-squared         =     0.9612
                                                            Root MSE          =      52.93
            
            ------------------------------------------------------------------------------
                         |               Robust
                  invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
                  mvalue |   .1189065   .0233249     5.10   0.000     .0725879    .1652252
                  kstock |   .3294687   .0456034     7.22   0.000     .2389094     .420028
                         |
                 company |
                      4  |   84.69127   75.50967     1.12   0.265    -65.25598    234.6385
                      5  |  -5.153231   88.42148    -0.06   0.954    -180.7408    170.4343
                      7  |   46.96136    88.1448     0.53   0.595    -128.0767    221.9995
                      8  |   55.84162   76.63162     0.73   0.468    -96.33359    208.0168
                         |
                   _cons |  -120.9414    91.0591    -1.33   0.187    -301.7667    59.88396
            ------------------------------------------------------------------------------
            Code:
            .
            . *JOINT REGRESSION
            
            .
            . regress invest c.gr1#(c.mvalue c.kstock) c.gr2#(c.mvalue c.kstock) c.gr3#(c.mvalue c
            > .kstock) i.company, robust
            
            Linear regression                               Number of obs     =        280
                                                            F(19, 260)        =     211.84
                                                            Prob > F          =     0.0000
                                                            R-squared         =     0.9443
                                                            Root MSE          =      60.35
            
            --------------------------------------------------------------------------------
                           |               Robust
                    invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            ---------------+----------------------------------------------------------------
            c.gr1#c.mvalue |   .1158152   .0208872     5.54   0.000     .0746856    .1569449
                           |
            c.gr1#c.kstock |   .3212348    .043267     7.42   0.000     .2360365    .4064331
                           |
            c.gr2#c.mvalue |   .1490376   .0362819     4.11   0.000     .0775939    .2204813
                           |
            c.gr2#c.kstock |   .1416635    .057272     2.47   0.014     .0288875    .2544395
                           |
            c.gr3#c.mvalue |   .1189065   .0233428     5.09   0.000     .0729414    .1648716
                           |
            c.gr3#c.kstock |   .3294687   .0456385     7.22   0.000     .2396006    .4193367
                           |
                   company |
                        2  |   189.5951   49.11379     3.86   0.000     92.88366    286.3065
                        3  |  -148.8852   47.96102    -3.10   0.002    -243.3266   -54.44369
                        4  |   65.95505   87.45755     0.75   0.451    -106.2602    238.1703
                        5  |  -19.16596   79.44627    -0.24   0.810     -175.606    137.2741
                        6  |   80.26711   87.18005     0.92   0.358    -91.40174     251.936
                        7  |   28.22514   87.29177     0.32   0.747    -143.6637     200.114
                        8  |   37.10539   87.46962     0.42   0.672    -135.1337    209.3444
                        9  |    52.1662    87.7645     0.59   0.553    -120.6535    224.9859
                       10  |   93.87806    85.9444     1.09   0.276    -75.35763    263.1138
                       13  |  -18.73622   125.2378    -0.15   0.881    -265.3457    227.8733
                       22  |   177.0339   114.0055     1.55   0.122    -47.45768    401.5255
                       52  |   60.55309   90.21582     0.67   0.503    -117.0936    238.1998
                       53  |  -23.88945   89.70061    -0.27   0.790    -200.5216    152.7427
                           |
                     _cons |  -102.2052   85.90685    -1.19   0.235    -271.3669    66.95661
            --------------------------------------------------------------------------------
            Code:
            . list company gr* if firstob, clean
            
                   company   gr1   gr2   gr3  
              1.         1     1     0     0  
             21.         2     1     0     0  
             41.         3     1     0     0  
             61.         4     0     0     1  
             81.         5     1     0     0  
            101.         6     0     1     0  
            121.         7     0     0     1  
            141.         8     0     0     1  
            161.         9     0     1     0  
            181.        10     0     1     0  
            201.        13     0     0     1  
            221.        22     0     1     0  
            241.        52     0     1     0  
            261.        53     0     0     1

            Comment


            • #7
              Thanks very much. I believe I have implemented what you have suggested above. I also realised using your final list that Country 134 is actually in 4 sub-samples. I have attempted to tackle this in a similar way to you suggested with 3 observations, but am unsure if I have done this correctly. Specifically, I am unsure whether the y variable I generated with the expand command is suitable for creating the third observation in the way which I have done. Do I need to generate 2 variables here?

              Code:
              clear all
              use "C:\Users\nicha\OneDrive\Documents\Masters\Thesis\Data\Country Panel\Country Panel Merged Dataset with Format.dta" 
              gen subsamp1 = inlist(Country,43,11,100,93,207,27)
              gen subsamp2 = inlist(Country, 178, 59,134,114,198)
              gen subsamp3 = inlist(Country, 74, 206,27,134)
              gen subsamp4 = inlist(Country, 128,105,99)
              gen subsamp5 = inlist(Country, 69,134,189)
              gen subsamp6 = inlist(Country, 207, 41,27,134)
              
              *Cross tab to check countries that are in both subsamps  
              
              bys Country: gen firstob= _n==1
              tab subsamp1 subsamp2 if firstob
              list Country if firstob & subsamp1 & subsamp2
              * shows no obs in both subsamp1 and 2 - which countries are in both samples?
              tab subsamp1 subsamp6 if firstob
              list Country if firstob & subsamp1 & subsamp6
              *Countries 207 is in both 1 and 6 
              tab subsamp1 subsamp3 if  firstob 
              list Country if firstob & subsamp1 & subsamp3
              tab subsamp3 subsamp5 if firstob 
              list Country if firstob & subsamp3 & subsamp6
              *Country 27 is in 3 subsamples : 1,3,6 !!!!!!!!!!!!!!!!!!! - need to duplicate observation twice- see statalist (5=Country 270
              tab subsamp2 subsamp5 if firstob
              list Country if firstob & subsamp2 & subsamp5
              *Country 134 is in both of these samples (2 and 5)
              
              *Separate regressions 
              *subsamp1 
              reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib27.Country if subsamp1 == 1 , cluster(CountryName)
              *subsamp2
              reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib27.Country if subsamp2 == 1 , cluster(CountryName)
              *subsamp3 
              reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib27.Country if subsamp3 == 1 ,cluster(CountryName)
              *subsamp4
              reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib27.Country if subsamp4 == 1 , cluster(CountryName)
              *subsamp5 
              reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib27.Country if subsamp5 == 1 , cluster(CountryName)
              *subsamp6 
              reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib27.Country if subsamp6 == 1 , cluster(CountryName)
              
              
              *issue: Country 27 is in 3 datasets - need to create 2 duplicates obs
              *NOW, KEEP ID=207 & ID=27 IN GROUP 1 AND DUPLICATE THESE FOR GROUP 6, ASSIGNING DIFFERENT IDs.
              *FOR FACTOR VARIABLES, THESE MUST BE INTEGERS. PRESERVE TO RESTORE ORIGINAL DATA SET LATER
              *first do for just 207 - 27 and 134 needed after 
              * 207 is in both 1 and 6. 
              * 134 is in both 2 and 5 
              * 27 need to create 2 observations , do twice - create obs 502 and 503 
              
              *Duplicate once : 207 
              preserve
              keep if inlist(Country, 207)
              
              *HERE I USE ID=500 & ID=52 (FOR ID 207 IN GROUP 2 AND ID 27 IN GROUP 2)
              *THESE VALUES ARE ARBITRARY, BUT MORE IMPORTANTLY, NO COMPANIES IN THE DATA SET HAVE THESE IDs
              replace Country=500 if Country==207
              
              *MAKE SURE NOT TO TAG THE FIRST GROUP AS WE WANT TO ASSIGN THESE EXCLUSIVELY TO THE SECOND
              replace subsamp1 = 0
              
              *SAVE TO APPEND TO THE ORIGINAL
              tempfile toappend
              save `toappend'
              restore, preserve
              append using `toappend'
              
              *UNTAG OVERLAPPING COMPANIES FROM SECOND GROUP
              replace subsamp6=0 if inlist(Country ,207)
              
              *DUPLICATE TWICE - observation 27 in subsamp1 
              * obs 502 is in subsamp 3 and 503 is in subsamp 6 
              keep if Country==27
              expand 2, gen(x)
              replace Country=501 if Country==27 & !x
              replace subsamp1=0 if Country==501
              replace subsamp6=0 if Country==501
              replace Country =502 if Country==27 & x
              replace subsamp1=0 if Country==502
              replace subsamp3=0 if Country==502
              drop x
              tempfile twice
              save `twice'
              restore, preserve
              
              *Duplicate 3 times for 134 - is in 4 subsamples 2,3,5 and 6 
              *Country 134 obs in subsamp 2
              keep if Country == 134 
              expand 3, gen(y)
              *This observation in subsamp 3
              replace Country == 503 if Country == 134 & !y
              replace subsamp2 = 0 if Country == 503
              replace subsamp5 = 0 if Country == 503
              replace subsamp6 = 0 if Country == 503
              *This observation in subsamp 5 
              replace Country ==  504 if Country == 134 & y
              replace subsamp2 = 0 if Country == 504
              replace subsamp3 = 0 if Country == 504
              replace subsamp6 = 0 if Country == 504
              *This observation in subsamp 6 - is this correct?????
              replace Country ==  505 if Country == 134 & y
              replace subsamp2 = 0 if Country == 505
              replace subsamp3 = 0 if Country == 505
              replace subsamp5 = 0 if Country == 505
              
              *Check observations are not in multiple subsamps
              list Country subsamp* if firstob, clean

              Comment


              • #8
                Can you post your data?

                Comment


                • #9
                  Yes of course. Here is an example.

                  Code:
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input str30 CountryName int year str3 CountryCode double(GDPCAP GDP GDPGROWTH) long Population double(Tourism Unemployment) long Country float(Host Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4)
                  "Albania" 1990 "ALB" 1880.0413396170275  6178834824.387625  -9.575640169486448  2031132       .              9.5 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 1991 "ALB" 1331.7597795490356  4350579530.232994  -29.58899770129115  2010074       . 9.10000038146973 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 1992 "ALB"  1243.390610540299 4037337804.6581616  -7.199999986164059  1990676       .             26.5 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 1993 "ALB" 1371.0966008720366  4424922235.738512   9.600000045405338  1973388       . 22.2999992370605 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 1994 "ALB" 1494.0411519659224  4792190780.412167    8.29999997982695  1957314       . 18.3999996185303 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 1995 "ALB"   1703.23715591804  5429552153.841033  13.299999992363581  1941355  304000 12.8999996185303 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 1996 "ALB" 1869.8168233283936  5923641400.259521   9.100000007716176  1941681  287000 12.3000001907349 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 1997 "ALB"  1676.082839921589   5276779759.35118 -10.920000000000016  1940477  119000 14.8999996185303 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 1998 "ALB"  1835.596721815642  5742719412.101891   8.830000000000027  1938219  184000 17.7000007629395 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 1999 "ALB" 2085.3711472230657  6482955944.321828  12.890000000000072  1936229  371000 18.3999996185303 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2000 "ALB" 2244.5648362582097 6933521382.4521885   6.949999999999903  1935652  317000 16.7999992370605 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2001 "ALB"  2453.557463926869  7508310305.057478   8.290000000000049  1929881  354000 16.3999996185303 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2002 "ALB" 2572.6522013717067  7849187592.907091   4.540000000000049  1937815  470000 15.8000001907349 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2003 "ALB" 2725.0967447186936  8283247666.794856    5.53000000000003  1945449  557000               15 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2004 "ALB"  2887.291291048561   8739654613.23524   5.509999999999863  1952585  645000 14.3999996185303 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2005 "ALB" 3062.5925044163087  9222957513.347157   5.530000000000086  1957782  748000 14.1000003814697 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2006 "ALB" 3263.8124001509846  9767112006.634628   5.899999999999878  1960854  937000 13.8000001907349 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2007 "ALB" 3485.2276282025928  10351185304.63138   5.980000000000004  1958838 1062000 15.9663000106812 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2008 "ALB"  3775.479708805628  11127524202.47875   7.500000000000156  1954566 1247000 13.0599002838135 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2009 "ALB"  3928.342143385504 11500296263.261787    3.34999999999998  1950306 1711000 13.6738996505737 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2010 "ALB" 4094.3602035923504 11926957254.628792  3.7099999999999227  1947666 2191000 14.0860004425049 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2011 "ALB"   4210.07700502783 12231094664.621826  2.5500000000000114  1961611 2469000  13.480899810791 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2012 "ALB"  4276.917643063649 12404776208.859451   1.419999999999959  1975480 3156000 13.3759002685547 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2013 "ALB"  4327.608231775726 12528823970.948051  1.0000000000000426  1987352 2857000 15.8659000396729 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2014 "ALB"  4413.335122319529 12750584155.233839  1.7700000000000529  1996460 3341000 17.4899997711182 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2015 "ALB"  4524.467507924287 13033647123.480019  2.2199999999999136  2000257 3784000 17.0799999237061 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2016 "ALB"  4683.519216507559 13470274302.116606   3.350000000000051  1997271 4070000                . 2 0 0 0 0 0 0 0 0 0 0
                  "Albania" 2017 "ALB"  4867.632464647651 13986932578.969046  3.8355438446510135  1994632 4643000            13.75 2 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 1990 "DZA"  3550.032671541718  91989749446.97946   .8000005799814147 13806990       . 21.2600002288818 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 1991 "DZA" 3422.6386182093443  90885871916.03632  -1.200000584390537 14291315       . 20.6000003814697 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 1992 "DZA" 3403.9034522240077  92521819701.82526  1.8000023010180257 14790717       . 24.3799991607666 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 1993 "DZA" 3259.8436797716563   90578860785.6483  -2.100000759214012 15304308       . 26.2299995422363 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 1994 "DZA" 3164.8985771543003  89763654164.59029  -.8999965488494865 15832316       . 27.7399997711182 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 1995 "DZA" 3223.5575604032097  93174668346.04738  3.7999947898763793 16374751  520000 31.8400001525879 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 1996 "DZA"  3297.863374558326  96994828322.43536   4.099998469755789 16906787  605000                . 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 1997 "DZA"  3281.102139095419   98061771373.7004   1.099999937850555 17456362  635000 25.4300003051758 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 1998 "DZA" 3397.4101977918867 103062925254.28166   5.100003610502341 18018559  678000                . 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 1999 "DZA" 3457.1370464975817  106360940460.5076  3.2000015505953456 18583470  749000                . 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2000 "DZA" 3541.0720367972917 110423586430.99423  3.8196784955987937 19144447  866000 29.7700004577637 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2001 "DZA" 3600.4372541095986 113745564598.73032  3.0083954661371592 19734527  901000 27.2999992370605 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2002 "DZA" 3754.5162751500056 120125920931.17308   5.609323189832736 20304857  988000 25.8999996185303 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2003 "DZA"  3974.175032022265 128777236288.58391  7.2018722440160445 20862869 1166000 23.7199993133545 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2004 "DZA" 4091.1442350797965 134316749131.75137   4.301624264364293 21416138 1234000 17.6499996185303 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2005 "DZA"  4273.312751467654 142251902308.52768   5.907791268081326 21963019 1443000 15.2700004577637 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2006 "DZA"  4282.328230917478 144648118986.03094  1.6844883186912796 22475875 1638000 12.2700004577637 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2007 "DZA"  4359.375747522446  149526919452.5767  3.3728751543716413 22965441 1743000  13.789999961853 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2008 "DZA"  4390.499632759569   153055956405.236   2.360134861053268 23433829 1772000 11.3299999237061 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2009 "DZA"  4386.038895588909  155554202821.6213  1.6322438375223243 23883916 1912000 10.1599998474121 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2010 "DZA"  4463.394674889505 161207268655.39215  3.6341453533424612 24315242 2070000 9.96000003814697 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2011 "DZA"   4504.92009813206 165869166838.53906  2.8918659946484837 24691566 2395000 9.96000003814697 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2012 "DZA"  4564.435016789671  171466867482.1632   3.374768650687841 25080157 2634000 10.9700002670288 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2013 "DZA"  4596.219627388071 176212451150.23447  2.7676388667711223 25457105 2733000 9.81999969482422 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2014 "DZA"  4675.885024476667 182889354514.36853   3.789121211668231 25800849 2301000  10.207200050354 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2015 "DZA"  4759.595241519403 189772334940.90765  3.7634669578312554 26106760 1710000 11.2061004638672 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2016 "DZA"  4827.724251387318  196034821993.4945  3.2999999997559684 26383347 2039000 10.2024002075195 3 0 0 0 0 0 0 0 0 0 0
                  "Algeria" 2017 "DZA"  4820.434063719884 199171379146.41522  1.6000000005227548 26652014 2451000 13.5699996948242 3 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 1990 "AND"   35780.5196725988 1950360346.8336878   3.781387589629162        .       .                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 1991 "AND" 35291.711409292446 2000016577.2760122  2.5460028718764107        .       .                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 1992 "AND" 34278.647100255075  2018600970.439821   .9292119562888956        .       .                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 1993 "AND"  32766.05967074008 1997779424.1846933 -1.0314840109578967        .       .                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 1994 "AND"  32633.82512747826 2045390257.5149548   2.383187690988038        .       .                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 1995 "AND"  32917.64882135711 2101791877.2436512   2.757499187329728        .       .                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 1996 "AND"  34175.26006841249  2199519738.003028   4.649740148750595        .       .                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 1997 "AND"  37293.28241329082 2398964977.7997584   9.067672199105132        .       .                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 1998 "AND" 38595.723209696414 2475606878.1163473   3.194790296058514        .       .                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 1999 "AND" 40035.482449085124 2577084005.2476096   4.099080836634087        . 2347000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2000 "AND"  40801.54213003222  2668012839.882807    3.52836129711109        . 2949000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2001 "AND" 41420.846177696934  2789321202.452289   4.546768319706089        . 3516000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2002 "AND"  42396.30239802838   2969818586.67949   6.471014670827913        . 3387000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2003 "AND" 45519.492383943405 3331207491.6417465  12.168719886904597        . 3138000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2004 "AND"  47032.86688847065  3585973903.044556   7.647869790219858        . 2791000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2005 "AND" 48831.929359938404  3851227772.830262   7.396982715365013        . 2418000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2006 "AND"  49708.40048930129 4025933064.0290008   4.536353119159912        . 2227000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2007 "AND" 48710.664620299576   4027543882.80023  .04001106689084111        . 2189000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2008 "AND"  43900.95170286543  3681577710.753998  -8.590003786766744        . 2059000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2009 "AND"  41979.86590139739 3545703433.7638264  -3.690653509588529        . 1830000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2010 "AND"   39736.3540626699 3355695364.2384105  -5.358825775333358        . 1808000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2011 "AND" 38205.771088791866 3199771534.4574075  -4.646543051633373        . 2242000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2012 "AND"  38190.58658537226 3148088242.8188205  -1.615218182986652        . 2238000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2013 "AND"  39104.30184901897 3159158337.7785444  .35164500185076975        . 2328000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2014 "AND" 40785.049228339616 3231113955.0167494  2.2776831530642028        . 2363000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2015 "AND"  41765.92035312352 3258326510.4285784   .8422035183741343        . 2663000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2016 "AND"  42958.55839253401  3319880351.133421   1.889124386639395        . 2831000                . 5 0 0 0 0 0 0 0 0 0 0
                  "Andorra" 2017 "AND" 43942.938186510895 3382068237.5248113  1.8731966159611488        .       .                . 5 0 0 0 0 0 0 0 0 0 0
                  "Angola"  1990 "AGO" 2614.4925039045625 31822141256.216652 -3.4500986836048355  5984034       .                . 6 0 0 0 0 0 0 0 0 0 0
                  "Angola"  1991 "AGO"  2560.063030537661  32137613010.45088   .9913592919288448  6159254       .                . 6 0 0 0 0 0 0 0 0 0 0
                  "Angola"  1992 "AGO" 2333.4765495055613 30261328943.397697  -5.838280728699502  6367924       .                . 6 0 0 0 0 0 0 0 0 0 0
                  "Angola"  1993 "AGO" 1716.2104308705007 23003628103.413578 -23.983417428756297  6599240       .                . 6 0 0 0 0 0 0 0 0 0 0
                  "Angola"  1994 "AGO" 1684.2152545782533 23311730287.409233  1.3393634369786014  6839479       .                . 6 0 0 0 0 0 0 0 0 0 0
                  "Angola"  1995 "AGO" 1878.7932657895108 26808489836.790936  15.000000026897695  7081533    9000                . 6 0 0 0 0 0 0 0 0 0 0
                  "Angola"  1996 "AGO" 2073.2149592902338 30439530825.347652  13.544369752501368  7285856   21000                . 6 0 0 0 0 0 0 0 0 0 0
                  "Angola"  1997 "AGO"  2164.081638131306 32653786720.212154   7.274277345367764  7497109   45000                . 6 0 0 0 0 0 0 0 0 0 0
                  "Angola"  1998 "AGO"  2204.909862849585 34185623674.956352   4.691146444574585  7721733   52000                . 6 0 0 0 0 0 0 0 0 0 0
                  "Angola"  1999 "AGO"  2190.087274328473  34931379545.11695   2.181489731623415  7968462   45000                . 6 0 0 0 0 0 0 0 0 0 0
                  "Angola"  2000 "AGO" 2189.5607527822303 35998401929.875435   3.054624233721796  8241956   51000                . 6 0 0 0 0 0 0 0 0 0 0
                  "Angola"  2001 "AGO" 2208.7915360030192 37512494194.487854   4.205998553940972  8512581   67000                . 6 0 0 0 0 0 0 0 0 0 0
                  "Angola"  2002 "AGO"  2426.431783481753  42638834053.56884  13.665686511013874  8815111   91000                . 6 0 0 0 0 0 0 0 0 0 0
                  "Angola"  2003 "AGO" 2412.3925214334604  43913671240.49369  2.9898500163565274  9143963  107000                . 6 0 0 0 0 0 0 0 0 0 0
                  "Angola"  2004 "AGO"   2582.64647618106  48723474948.03264  10.952861766437167  9492530  194000 23.6427001953125 6 0 0 0 0 0 0 0 0 0 0
                  "Angola"  2005 "AGO"  2866.434693689993  56046084738.63072  15.028915319377802  9856402  210000                . 6 0 0 0 0 0 0 0 0 0 0
                  end

                  Comment


                  • #10
                    I don't think that dataex will work here as the data set is too large. Just attach the full data set in .dta format.

                    Comment


                    • #11
                      I tried multiple times to upload the data set in .dta format but I the forum didn't seem to allow it apologies.

                      I copied the data into excel and have attached it below. I hope this is suitable.

                      Statalist Country Panel Data.xlsx

                      Comment


                      • #12
                        Your data set is too big to use the least squares dummy variables (LSDV) estimator. You will be attempting to invert a very large matrix using brute-force, and this is not necessary as you do not need the dummy coefficients. Install Sergio Correia's reghdfe from SSC which allows you to absorb multiple fixed effects. The second point is that if you simultaneously estimate all 6 groups, one variable is collinear with the fixed effects, and you cannot obtain its estimate. This is a feature of your data. Five groups are OK, so you may want to check the data and see if you can redefine some of the groups to break the collinearity. In any case, the code below will give you what you want.


                        Code:
                        use "Statalist Country Panel Data.dta"
                        preserve
                        keep if inlist(Country, 27, 134, 207)
                        replace Country= Country*10
                        replace CountryName= CountryName+"x"
                        tempfile one
                        save `one'
                        
                        restore, preserve
                        keep if inlist(Country, 27, 134)
                        expand 2, gen(x)
                        drop if Country==27 & x
                        replace Country= Country*100 if !x
                        replace Country= Country*1000 if x
                        replace CountryName= CountryName+"xx" if !x
                        replace CountryName= CountryName+"xxx" if x
                        drop x
                        tempfile two
                        save `two'
                        restore, preserve
                        
                        append using `one'
                        append using `two'
                        
                        gen subsamp1 = inlist(Country,43,11,100,93,207,27)
                        gen subsamp2 = inlist(Country, 178, 59,134,114,198)
                        gen subsamp3 = inlist(Country, 74, 206,270,1340)
                        gen subsamp4 = inlist(Country, 128,105,99)
                        gen subsamp5 = inlist(Country, 69,13400,189)
                        gen subsamp6 = inlist(Country, 207, 41,2700,134000)
                        drop firstob
                        bys Country: gen firstob= _n==1
                        list CountryName subsamp1- subsamp6 if firstob
                        
                        *Separate regressions
                        *subsamp1
                        reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib27.Country if subsamp1, cluster(CountryName)
                        *subsamp2
                        reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year i.Country if subsamp2, cluster(CountryName)
                        *subsamp3
                        reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib270.Country if subsamp3,cluster(CountryName)
                        *subsamp4
                        reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year i.Country if subsamp4, cluster(CountryName)
                        *subsamp5
                        reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year i.Country if subsamp5, cluster(CountryName)
                        *subsamp6
                        reg OwnGDPGROWTH Pre4 Pre3 Pre2 Pre1 t Post1 Post2 Post3 Post4 i.year ib2700.Country if subsamp6, cluster(CountryName)
                        
                        
                        *NO BRUTE-FORCE INVERSION - USE REGHDFE - SSC INSTALL
                        
                        *Joint regression
                        reghdfe OwnGDPGROWTH  c.subsamp1#(c.Pre4 c.Pre3 c.Pre2 c.Pre1 c.t c.Post1 c.Post2 c.Post3 c.Post4)  c.subsamp2#(c.Pre4 c.Pre3 c.Pre2 c.Pre1 c.t c.Post1 c.Post2 c.Post3 c.Post4)  c.subsamp3#(c.Pre4 c.Pre3 c.Pre2 c.Pre1 c.t c.Post1 c.Post2 c.Post3 c.Post4)  c.subsamp4#(c.Pre4 c.Pre3 c.Pre2 c.Pre1 c.t c.Post1 c.Post2 c.Post3 c.Post4)  c.subsamp5#(c.Pre4 c.Pre3 c.Pre2 c.Pre1 c.t c.Post1 c.Post2 c.Post3 c.Post4) , a(i.Country#c.subsamp1 i.Country#c.subsamp2 i.Country#c.subsamp3 i.Country#c.subsamp4 i.Country#c.subsamp5 i.year#c.subsamp1 i.year#c.subsamp2 i.year#c.subsamp3 i.year#c.subsamp4 i.year#c.subsamp5) cluster(CountryName) dofadjustments(clusters)
                        Last edited by Andrew Musau; 20 May 2019, 15:02.

                        Comment


                        • #13
                          That's great thank you.

                          I had a few small issues implementing what you suggested. When checking the samples using the list command I noticed Country 207 is still in subsamp1 and subsamp6. Am I correct in saying it should be Country 2070 in subsamp6?

                          I also have an issue when i run the join regression using reghdfe. I get the error message:

                          Code:
                          (warning: no intercepts terms in absorb(); regression lacks constant term)
                          (MWFE estimator converged in 2 iterations)
                          warning: missing F statistic; dropped variables due to collinearity or too few clusters
                          class FixedEffects undefined
                          r(3000);
                          , which I was unable to interpret.
                          *I believe I have now solved this issue using : regdhfe, compile.

                          However, the c.subsamp6#c.Post4 estimate is still omitted. And is it possible to obtain an average result across the 6 samples?

                          Additionally, is the 'drop firstob' necessary if I have not previously defined first ob? I get an error saying 'variable firstob not found'.

                          Thanks again.
                          Last edited by Nicholas Hamer; 21 May 2019, 04:49.

                          Comment


                          • #14
                            That's great thank you.

                            I had a few small issues implementing what you suggested. When checking the samples using the list command I noticed Country 207 is still in subsamp1 and subsamp6. Am I correct in saying it should be Country 2070 in subsamp6?
                            Yes, that explains my collinearity problem when including the last subsample, good catch! With the following change,

                            Code:
                            drop subsamp6
                            gen subsamp6 = inlist(Country, 2070, 41,2700,134000)
                            you should now be able to include all six subsamples with no collinearity reported. The full command is

                            Code:
                            reghdfe OwnGDPGROWTH  c.subsamp1#(c.Pre4 c.Pre3 c.Pre2 c.Pre1 c.t c.Post1 c.Post2 c.Post3 c.Post4)  c.subsamp2#(c.Pre4 c.Pre3 c.Pre2 c.Pre1 c.t c.Post1 c.Post2 c.Post3 c.Post4)  c.subsamp3#(c.Pre4 c.Pre3 c.Pre2 c.Pre1 c.t c.Post1 c.Post2 c.Post3 c.Post4)  c.subsamp4#(c.Pre4 c.Pre3 c.Pre2 c.Pre1 c.t c.Post1 c.Post2 c.Post3 c.Post4)  c.subsamp5#(c.Pre4 c.Pre3 c.Pre2 c.Pre1 c.t c.Post1 c.Post2 c.Post3 c.Post4) c.subsamp6#(c.Pre4 c.Pre3 c.Pre2 c.Pre1 c.t c.Post1 c.Post2 c.Post3 c.Post4) , a(i.Country#c.subsamp1 i.Country#c.subsamp2 i.Country#c.subsamp3 i.Country#c.subsamp4 i.Country#c.subsamp5 i.Country#c.subsamp6 i.year#c.subsamp1 i.year#c.subsamp2 i.year#c.subsamp3 i.year#c.subsamp4 i.year#c.subsamp5 i.year#c.subsamp6)  cluster(CountryName) dofadjustments(clusters)
                            , which I was unable to interpret.
                            *I believe I have now solved this issue using : regdhfe, compile.

                            However, the c.subsamp6#c.Post4 estimate is still omitted. And is it possible to obtain an average result across the 6 samples?

                            Additionally, is the 'drop firstob' necessary if I have not previously defined first ob? I get an error saying 'variable firstob not found'.

                            Thanks again.
                            Just delete that line "drop firstob". I was running your earlier code in #7 and had to generate the variable again after duplicating observations. Ignore the warnings from reghdfe, the intercepts are included in the absorbed fixed effects. You can now use lincom as you initially intented. For example, you refer to the first coefficient as follows:

                            Code:
                            . di _b[c.subsamp1#c.Pre4]
                            5.0928068
                            Last edited by Andrew Musau; 21 May 2019, 05:14.

                            Comment


                            • #15
                              Ok thanks, I have successfully implemented what you suggested and obtained my average estimates.

                              One last thing I was wondering is if there is shortcut to weighting these estimates by their standard errors when I use lincom.

                              Comment

                              Working...
                              X