Announcement

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

  • running the regression at the disaggregated level

    Dear all,

    am struggling with my project in STATA. I have data on bilateral trade for Germany at the sectoral level. I wanna regress the export volume on exchange rate and GDP for each sector separetly. I have no idea how I obtain coefficients for each sector (variable HsS since I have almost 900 sectors and 26 countries, including Germany. I have panel data on German trade with these countries for every sector. I defined data as panel by using egen id=group(partnernr HSspecific), where partnernr is a partner country for Germany and HSspecific is a sector. I have id's for each sector for very country. Stata created 152031 such ids. However, my aim is to obtain elasticities on export and GDP for each sector. Now I can only run the general regression, taking export as dependent variable and export and GDP as variables of interest. I wanna obtain almost 900 coeffients for each sector. Any suggestions how can I approach this problem?

  • #2
    Here is an example where the region variable would represent sector in your dataset. This variable is labeled, so should yours to identify which sector is which. Eventually, you can export the matrix holding the results (1800 coefficients as you have 2 variables).

    Code:
    sysuse census, clear
    levelsof region, local(regions)
    clear matrix
    local rowname
    foreach region of local regions{
        regress pop marriage medage if region==`region', robust
        mat res= nullmat(res)\(r(table)[1..6, 1..2])'
        local rowname "`rowname' marriage_`=strtoname("`: lab `:val lab region' `region''")' "
        local rowname "`rowname' medage_`=strtoname("`: lab `:val lab region' `region''")' "
    }
    mat rowname res= `rowname'
    mat list res
    Res.:

    Code:
    . mat list res
    
    res[8,6]
                           b          se           t      pvalue          ll          ul
     marriage_NE   122.14502   2.4548658   49.756293   4.420e-09   116.13818   128.15186
       medage_NE   185153.22   108060.88   1.7134158   .13746915   -79262.23   449568.67
    marriage_N~l    106.9078   2.2282423   47.978534   3.720e-12   101.86716   111.94843
    medage_N_C~l  -215888.49   159379.68  -1.3545547   .20858445  -576430.38    144653.4
    marriage_S~h   76.587289   1.4079049   54.398056   1.007e-16   73.545695   79.628883
    medage_South   145251.43   75457.272   1.9249494   .07639785  -17764.097   308266.95
    marriage_W~t   98.338812   26.655029   3.6893155   .00418157   38.947706   157.72992
     medage_West  -368691.09   402890.74  -.91511433   .38166844  -1266387.6   529005.43
    
    .

    Comment


    • #3
      Thank you for your answer. For my data I changed the code as follows:

      levelsof HSspecific, local(sectors)
      clear matrix
      local rowname
      foreach HSspecific of local sectors{
      regress d.tradevalue_ex d.GDP_CAP d.EXCH if HSspecific==`HSspecific', robust
      mat res= nullmat(res)\(r(table)[1..6, 1..2])'
      local rowname "`rowname' GDP_CAP_`=strtoname("`: lab `:val lab HSspecific' `HSspecific''")' "
      local rowname "`rowname' EXCH_`=strtoname("`: lab `:val lab HSSpecific' `HSspecific''")' "
      }
      mat rowname res= `rowname'
      mat list res

      However, it doesn't work. I see : matrix res not found.

      I run the code for data in census and it works. I don't know what I'm doing wrong with my data that it doesn't wanna work. Could you please help me?

      Comment


      • #4
        Can you copy and paste the entire output from Stata? It is possible that some regressions are failing and thereby breaking the loop. Better still, if you can post a data example, that would help.

        Code:
        dataex tradevalue_ex GDP_CAP EXCH HSspecific sector year in 1/100

        Comment


        • #5
          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input float id double(tradevalue_ex GDP_CAP EXCH) long HSspecific int year
           1  1993940000 18165.37749 1.2927237591260599     0 1991
           1  2476527000   19136.159 1.1468820265633959     0 1992
           1  2466331000 20162.39481  1.124279752837919     0 1993
           1  2924031000 21397.51238 1.1864691485595933     0 1994
           1  3674149000 22405.57233 1.0623409739943255     0 1995
           1  3488102000 23268.40581 1.1775705018011895     0 1996
           1  3388295168 24442.26533 1.2869835037875952     0 1997
           1  3495591936 25671.58245 1.1054380445127585     0 1998
           1  3446397440 27121.29636  .6053634455274293     0 1999
           1  3108689000 28304.65674   .627718194674252     0 2000
           1  3196680000 29561.39887  .5774845053031988     0 2001
           1  3694849000 30800.45213  .5745846697624504     0 2002
           1  4760082000 32352.94183  .5733444482815195     0 2003
           1  5767556000 33962.01514   .591226453157913     0 2004
           1  6243205000 35642.41871  .6138347163705139     0 2005
           1  6900683000   37893.839  .5997354364626661     0 2006
           1  7971935000 39658.37385  .6105674760184742     0 2007
           1  9752454000  40105.1103  .5703196082600038     0 2008
           1  8786727000 41636.49607  .5591670246824842     0 2009
           1 10415729072 42809.92706  .6919253554413991     0 2010
           1 11596680586 44429.55951  .7410429787785415     0 2011
           1 12077788607 43883.37889   .805899036870938     0 2012
           1 11441547170 47761.90126  .7268910950231656     0 2013
           1 10395172049 47603.88088  .6785227182172638     0 2014
           2           0 30800.45213  .5745846697624504 10110 2002
           2           0 32352.94183  .5733444482815195 10110 2003
           2           0 33962.01514   .591226453157913 10110 2004
           2           0 35642.41871  .6138347163705139 10110 2005
           2        4000   37893.839  .5997354364626661 10110 2006
           2           0 39658.37385  .6105674760184742 10110 2007
           2       42000 41636.49607  .5591670246824842 10110 2009
           2           0 42809.92706  .6919253554413991 10110 2010
           2           0 44429.55951  .7410429787785415 10110 2011
           3       57000 21397.51238 1.1864691485595933 10111 1994
           3           0 23268.40581 1.1775705018011895 10111 1996
           3           0 24442.26533 1.2869835037875952 10111 1997
           3           0 27121.29636  .6053634455274293 10111 1999
           3           0 29561.39887  .5774845053031988 10111 2001
           4       51000 18165.37749 1.2927237591260599 10119 1991
           4           0   19136.159 1.1468820265633959 10119 1992
           4           0 20162.39481  1.124279752837919 10119 1993
           4           0 21397.51238 1.1864691485595933 10119 1994
           4           0 22405.57233 1.0623409739943255 10119 1995
           4           0 23268.40581 1.1775705018011895 10119 1996
           4           0 24442.26533 1.2869835037875952 10119 1997
           4           0 25671.58245 1.1054380445127585 10119 1998
           4           0 27121.29636  .6053634455274293 10119 1999
           4       64000 28304.65674   .627718194674252 10119 2000
           4       73000 29561.39887  .5774845053031988 10119 2001
           5           0 43883.37889   .805899036870938 10121 2012
           5           0 47603.88088  .6785227182172638 10121 2014
           5           0  50150.6522  .6715819582328011 10121 2016
           5           0 50699.17511   .678444168360655 10121 2017
           6     4102682 43883.37889   .805899036870938 10129 2012
           6     4037158 47761.90126  .7268910950231656 10129 2013
           6     3253208 47603.88088  .6785227182172638 10129 2014
           6     1604548 47232.62912  .6771114242130912 10129 2015
           6     2431541  50150.6522  .6715819582328011 10129 2016
           6     2047946 50699.17511   .678444168360655 10129 2017
           6     1118930 53427.25132  .6326695923560564 10129 2018
           7       59000 30800.45213  .5745846697624504 10190 2002
           7      199000 32352.94183  .5733444482815195 10190 2003
           7       54000 33962.01514   .591226453157913 10190 2004
           7     1737000   37893.839  .5997354364626661 10190 2006
           7      597000 39658.37385  .6105674760184742 10190 2007
           7     2538000  40105.1103  .5703196082600038 10190 2008
           7     3301000 41636.49607  .5591670246824842 10190 2009
           7     1701321 42809.92706  .6919253554413991 10190 2010
           7     2404046 44429.55951  .7410429787785415 10190 2011
           8        1000 22405.57233 1.0623409739943255 10210 1995
           8       74000 39658.37385  .6105674760184742 10210 2007
           9        1000 25671.58245 1.1054380445127585 10310 1998
          10        6625 42809.92706  .6919253554413991 10511 2010
          11        6000 18165.37749 1.2927237591260599 10600 1991
          11        3000   19136.159 1.1468820265633959 10600 1992
          11        3000 20162.39481  1.124279752837919 10600 1993
          11           0 21397.51238 1.1864691485595933 10600 1994
          11           0 22405.57233 1.0623409739943255 10600 1995
          11           0 23268.40581 1.1775705018011895 10600 1996
          11        3460 24442.26533 1.2869835037875952 10600 1997
          11        6531 27121.29636  .6053634455274293 10600 1999
          11           0 28304.65674   .627718194674252 10600 2000
          11        9000 29561.39887  .5774845053031988 10600 2001
          12           0 39658.37385  .6105674760184742 10611 2007
          13           0 47232.62912  .6771114242130912 10613 2015
          14           0 30800.45213  .5745846697624504 10619 2002
          14        1000 32352.94183  .5733444482815195 10619 2003
          14        1000 33962.01514   .591226453157913 10619 2004
          14        1000 35642.41871  .6138347163705139 10619 2005
          14           0   37893.839  .5997354364626661 10619 2006
          14           0 39658.37385  .6105674760184742 10619 2007
          14        1000  40105.1103  .5703196082600038 10619 2008
          14           0 41636.49607  .5591670246824842 10619 2009
          14           0 42809.92706  .6919253554413991 10619 2010
          14         278 44429.55951  .7410429787785415 10619 2011
          14           0 43883.37889   .805899036870938 10619 2012
          14           0 47761.90126  .7268910950231656 10619 2013
          14        1785 47603.88088  .6785227182172638 10619 2014
          14       29185 47232.62912  .6771114242130912 10619 2015
          14       72806  50150.6522  .6715819582328011 10619 2016
          end
          I don't have variable sectors. The variable sector is denoted as HSspecific. I typed in the command before: levelsof HSspecific, local(sectors). However it didn't generate sectors

          Comment


          • #6
            Thanks for the data example. You will have to add capture to your regress command as some regressions may fail due to insufficient observations. capture allows the loop to continue by suppressing the insufficient observations error message. See

            Code:
            help capture
            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input float id double(tradevalue_ex GDP_CAP EXCH) long HSspecific int year
             1  1993940000 18165.37749 1.2927237591260599     0 1991
             1  2476527000   19136.159 1.1468820265633959     0 1992
             1  2466331000 20162.39481  1.124279752837919     0 1993
             1  2924031000 21397.51238 1.1864691485595933     0 1994
             1  3674149000 22405.57233 1.0623409739943255     0 1995
             1  3488102000 23268.40581 1.1775705018011895     0 1996
             1  3388295168 24442.26533 1.2869835037875952     0 1997
             1  3495591936 25671.58245 1.1054380445127585     0 1998
             1  3446397440 27121.29636  .6053634455274293     0 1999
             1  3108689000 28304.65674   .627718194674252     0 2000
             1  3196680000 29561.39887  .5774845053031988     0 2001
             1  3694849000 30800.45213  .5745846697624504     0 2002
             1  4760082000 32352.94183  .5733444482815195     0 2003
             1  5767556000 33962.01514   .591226453157913     0 2004
             1  6243205000 35642.41871  .6138347163705139     0 2005
             1  6900683000   37893.839  .5997354364626661     0 2006
             1  7971935000 39658.37385  .6105674760184742     0 2007
             1  9752454000  40105.1103  .5703196082600038     0 2008
             1  8786727000 41636.49607  .5591670246824842     0 2009
             1 10415729072 42809.92706  .6919253554413991     0 2010
             1 11596680586 44429.55951  .7410429787785415     0 2011
             1 12077788607 43883.37889   .805899036870938     0 2012
             1 11441547170 47761.90126  .7268910950231656     0 2013
             1 10395172049 47603.88088  .6785227182172638     0 2014
             2           0 30800.45213  .5745846697624504 10110 2002
             2           0 32352.94183  .5733444482815195 10110 2003
             2           0 33962.01514   .591226453157913 10110 2004
             2           0 35642.41871  .6138347163705139 10110 2005
             2        4000   37893.839  .5997354364626661 10110 2006
             2           0 39658.37385  .6105674760184742 10110 2007
             2       42000 41636.49607  .5591670246824842 10110 2009
             2           0 42809.92706  .6919253554413991 10110 2010
             2           0 44429.55951  .7410429787785415 10110 2011
             3       57000 21397.51238 1.1864691485595933 10111 1994
             3           0 23268.40581 1.1775705018011895 10111 1996
             3           0 24442.26533 1.2869835037875952 10111 1997
             3           0 27121.29636  .6053634455274293 10111 1999
             3           0 29561.39887  .5774845053031988 10111 2001
             4       51000 18165.37749 1.2927237591260599 10119 1991
             4           0   19136.159 1.1468820265633959 10119 1992
             4           0 20162.39481  1.124279752837919 10119 1993
             4           0 21397.51238 1.1864691485595933 10119 1994
             4           0 22405.57233 1.0623409739943255 10119 1995
             4           0 23268.40581 1.1775705018011895 10119 1996
             4           0 24442.26533 1.2869835037875952 10119 1997
             4           0 25671.58245 1.1054380445127585 10119 1998
             4           0 27121.29636  .6053634455274293 10119 1999
             4       64000 28304.65674   .627718194674252 10119 2000
             4       73000 29561.39887  .5774845053031988 10119 2001
             5           0 43883.37889   .805899036870938 10121 2012
             5           0 47603.88088  .6785227182172638 10121 2014
             5           0  50150.6522  .6715819582328011 10121 2016
             5           0 50699.17511   .678444168360655 10121 2017
             6     4102682 43883.37889   .805899036870938 10129 2012
             6     4037158 47761.90126  .7268910950231656 10129 2013
             6     3253208 47603.88088  .6785227182172638 10129 2014
             6     1604548 47232.62912  .6771114242130912 10129 2015
             6     2431541  50150.6522  .6715819582328011 10129 2016
             6     2047946 50699.17511   .678444168360655 10129 2017
             6     1118930 53427.25132  .6326695923560564 10129 2018
             7       59000 30800.45213  .5745846697624504 10190 2002
             7      199000 32352.94183  .5733444482815195 10190 2003
             7       54000 33962.01514   .591226453157913 10190 2004
             7     1737000   37893.839  .5997354364626661 10190 2006
             7      597000 39658.37385  .6105674760184742 10190 2007
             7     2538000  40105.1103  .5703196082600038 10190 2008
             7     3301000 41636.49607  .5591670246824842 10190 2009
             7     1701321 42809.92706  .6919253554413991 10190 2010
             7     2404046 44429.55951  .7410429787785415 10190 2011
             8        1000 22405.57233 1.0623409739943255 10210 1995
             8       74000 39658.37385  .6105674760184742 10210 2007
             9        1000 25671.58245 1.1054380445127585 10310 1998
            10        6625 42809.92706  .6919253554413991 10511 2010
            11        6000 18165.37749 1.2927237591260599 10600 1991
            11        3000   19136.159 1.1468820265633959 10600 1992
            11        3000 20162.39481  1.124279752837919 10600 1993
            11           0 21397.51238 1.1864691485595933 10600 1994
            11           0 22405.57233 1.0623409739943255 10600 1995
            11           0 23268.40581 1.1775705018011895 10600 1996
            11        3460 24442.26533 1.2869835037875952 10600 1997
            11        6531 27121.29636  .6053634455274293 10600 1999
            11           0 28304.65674   .627718194674252 10600 2000
            11        9000 29561.39887  .5774845053031988 10600 2001
            12           0 39658.37385  .6105674760184742 10611 2007
            13           0 47232.62912  .6771114242130912 10613 2015
            14           0 30800.45213  .5745846697624504 10619 2002
            14        1000 32352.94183  .5733444482815195 10619 2003
            14        1000 33962.01514   .591226453157913 10619 2004
            14        1000 35642.41871  .6138347163705139 10619 2005
            14           0   37893.839  .5997354364626661 10619 2006
            14           0 39658.37385  .6105674760184742 10619 2007
            14        1000  40105.1103  .5703196082600038 10619 2008
            14           0 41636.49607  .5591670246824842 10619 2009
            14           0 42809.92706  .6919253554413991 10619 2010
            14         278 44429.55951  .7410429787785415 10619 2011
            14           0 43883.37889   .805899036870938 10619 2012
            14           0 47761.90126  .7268910950231656 10619 2013
            14        1785 47603.88088  .6785227182172638 10619 2014
            14       29185 47232.62912  .6771114242130912 10619 2015
            14       72806  50150.6522  .6715819582328011 10619 2016
            end
            
            xtset id year
            levelsof HSspecific, local(sectors)
            clear matrix
            local rowname
            foreach sector of local sectors{
                capture{
                    regress d.tradevalue_ex d.GDP_CAP d.EXCH if HSspecific==`sector', robust
                    mat res= nullmat(res)\(r(table)[1..6, 1..2])'
                    local rowname "`rowname'  GDP_CAP_sec`sector'"
                    local rowname "`rowname' EXCH_sec`sector'"
                }
            }
            mat rowname res= `rowname'
            mat list res
            Res.:

            Code:
            . mat list res
            
            res[14,6]
                                   b          se           t      pvalue          ll          ul
            GDP_CAP_sec0  -36067.216   241201.65  -.14953138   .88263197  -539205.05   467070.62
               EXCH_sec0   1.115e+09   7.548e+08   1.4771263   .15521606  -4.596e+08   2.690e+09
            GDP_CA~10110  -.87240049   10.559898  -.08261448   .93812708  -30.191377   28.446576
            EXCH_s~10110  -307792.26   85032.228  -3.6197129   .02236289  -543879.57  -71704.944
            GDP_CA~10119   94.809481   61.512984   1.5412922   .16714675  -50.645613   240.26457
            EXCH_s~10119   81944.821   57705.377   1.4200552   .19856008  -54506.713   218396.35
            GDP_CA~10129   400.96254   238.91788   1.6782442   .19189212  -359.38079   1161.3059
            EXCH_s~10129    10205822    10557763   .96666514   .40501706   -23393693    43805336
            GDP_CA~10190  -1026.6249   547.70883  -1.8743991   .13414691  -2547.3085   494.05855
            EXCH_s~10190   -14278456   3869163.1  -3.6903215   .02101281   -25020975  -3535936.8
            GDP_CA~10600   7.9431552   15.400839   .51576119   .62800895  -31.645963   47.532273
            EXCH_s~10600  -1240.2516   13884.852  -.08932408   .93229198    -36932.4   34451.897
            GDP_CA~10619   .49965434   4.3965949   .11364575   .91156628  -9.1771859   10.176495
            EXCH_s~10619  -22110.944   35226.434  -.62768046   .54302366  -99643.802   55421.914
            
            .

            Comment


            • #7
              Now it works. Thank you so much!

              Comment


              • #8
                I've noticed the matrix with results displays only sectors from sector 0 till sector 40690. My sectors are numbered till 999999. I have almost 900 sectors. I investigate the influence of GDP and exchange rate on German trade. So I should obtain 1800 coefficients. Even though I have insufficient observations only the first half of the sectors seems suspicious to me.

                Comment


                • #9
                  What is your flavor of Stata? If it is IC, the matrix limit is 800 by 800. See

                  Code:
                  help limits
                  levelsof can handle 900 values with no issues.

                  Code:
                  clear
                  set obs 900
                  gen id=_n
                  levelsof id, local(levels)
                  di "`levels'"
                  If it is not the flavor of Stata, you are probably overestimating the number of regressions in your data. Try manually using a sector not included in the output.

                  Res.:

                  . levelsof id, local(levels)
                  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
                  > 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
                  > 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
                  > 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 13
                  > 9 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 1
                  > 67 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
                  > 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
                  > 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 25
                  > 0 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 2
                  > 78 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
                  > 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
                  > 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 36
                  > 1 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 3
                  > 89 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
                  > 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
                  > 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 47
                  > 2 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 5
                  > 00 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
                  > 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
                  > 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 58
                  > 3 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 6
                  > 11 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
                  > 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
                  > 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 69
                  > 4 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 7
                  > 22 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
                  > 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
                  > 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 80
                  > 5 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 8
                  > 33 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860
                  > 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
                  > 889 890 891 892 893 894 895 896 897 898 899 900

                  .
                  . di "`levels'"
                  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
                  > 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
                  > 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
                  > 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 13
                  > 9 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 1
                  > 67 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
                  > 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
                  > 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 25
                  > 0 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 2
                  > 78 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
                  > 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
                  > 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 36
                  > 1 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 3
                  > 89 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
                  > 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
                  > 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 47
                  > 2 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 5
                  > 00 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
                  > 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
                  > 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 58
                  > 3 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 6
                  > 11 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
                  > 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
                  > 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 69
                  > 4 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 7
                  > 22 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
                  > 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
                  > 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 80
                  > 5 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 8
                  > 33 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860
                  > 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
                  > 889 890 891 892 893 894 895 896 897 898 899 900

                  .

                  Comment


                  • #10
                    Thank you for your answer. I use Stata IC/16.1. I applied the regression for sector 999999 and I got the results. So it must be flavor of my stata. After typing levelsof command I got the matrix with sectors till 999999. Is there any solution I could obtain my results?

                    Comment


                    • #11
                      Yes, you will hit the matrix limits with Stata IC. Let us try frames instead:

                      Code:
                      * Example generated by -dataex-. To install: ssc install dataex
                      clear
                      input float id double(tradevalue_ex GDP_CAP EXCH) long HSspecific int year
                       1  1993940000 18165.37749 1.2927237591260599     0 1991
                       1  2476527000   19136.159 1.1468820265633959     0 1992
                       1  2466331000 20162.39481  1.124279752837919     0 1993
                       1  2924031000 21397.51238 1.1864691485595933     0 1994
                       1  3674149000 22405.57233 1.0623409739943255     0 1995
                       1  3488102000 23268.40581 1.1775705018011895     0 1996
                       1  3388295168 24442.26533 1.2869835037875952     0 1997
                       1  3495591936 25671.58245 1.1054380445127585     0 1998
                       1  3446397440 27121.29636  .6053634455274293     0 1999
                       1  3108689000 28304.65674   .627718194674252     0 2000
                       1  3196680000 29561.39887  .5774845053031988     0 2001
                       1  3694849000 30800.45213  .5745846697624504     0 2002
                       1  4760082000 32352.94183  .5733444482815195     0 2003
                       1  5767556000 33962.01514   .591226453157913     0 2004
                       1  6243205000 35642.41871  .6138347163705139     0 2005
                       1  6900683000   37893.839  .5997354364626661     0 2006
                       1  7971935000 39658.37385  .6105674760184742     0 2007
                       1  9752454000  40105.1103  .5703196082600038     0 2008
                       1  8786727000 41636.49607  .5591670246824842     0 2009
                       1 10415729072 42809.92706  .6919253554413991     0 2010
                       1 11596680586 44429.55951  .7410429787785415     0 2011
                       1 12077788607 43883.37889   .805899036870938     0 2012
                       1 11441547170 47761.90126  .7268910950231656     0 2013
                       1 10395172049 47603.88088  .6785227182172638     0 2014
                       2           0 30800.45213  .5745846697624504 10110 2002
                       2           0 32352.94183  .5733444482815195 10110 2003
                       2           0 33962.01514   .591226453157913 10110 2004
                       2           0 35642.41871  .6138347163705139 10110 2005
                       2        4000   37893.839  .5997354364626661 10110 2006
                       2           0 39658.37385  .6105674760184742 10110 2007
                       2       42000 41636.49607  .5591670246824842 10110 2009
                       2           0 42809.92706  .6919253554413991 10110 2010
                       2           0 44429.55951  .7410429787785415 10110 2011
                       3       57000 21397.51238 1.1864691485595933 10111 1994
                       3           0 23268.40581 1.1775705018011895 10111 1996
                       3           0 24442.26533 1.2869835037875952 10111 1997
                       3           0 27121.29636  .6053634455274293 10111 1999
                       3           0 29561.39887  .5774845053031988 10111 2001
                       4       51000 18165.37749 1.2927237591260599 10119 1991
                       4           0   19136.159 1.1468820265633959 10119 1992
                       4           0 20162.39481  1.124279752837919 10119 1993
                       4           0 21397.51238 1.1864691485595933 10119 1994
                       4           0 22405.57233 1.0623409739943255 10119 1995
                       4           0 23268.40581 1.1775705018011895 10119 1996
                       4           0 24442.26533 1.2869835037875952 10119 1997
                       4           0 25671.58245 1.1054380445127585 10119 1998
                       4           0 27121.29636  .6053634455274293 10119 1999
                       4       64000 28304.65674   .627718194674252 10119 2000
                       4       73000 29561.39887  .5774845053031988 10119 2001
                       5           0 43883.37889   .805899036870938 10121 2012
                       5           0 47603.88088  .6785227182172638 10121 2014
                       5           0  50150.6522  .6715819582328011 10121 2016
                       5           0 50699.17511   .678444168360655 10121 2017
                       6     4102682 43883.37889   .805899036870938 10129 2012
                       6     4037158 47761.90126  .7268910950231656 10129 2013
                       6     3253208 47603.88088  .6785227182172638 10129 2014
                       6     1604548 47232.62912  .6771114242130912 10129 2015
                       6     2431541  50150.6522  .6715819582328011 10129 2016
                       6     2047946 50699.17511   .678444168360655 10129 2017
                       6     1118930 53427.25132  .6326695923560564 10129 2018
                       7       59000 30800.45213  .5745846697624504 10190 2002
                       7      199000 32352.94183  .5733444482815195 10190 2003
                       7       54000 33962.01514   .591226453157913 10190 2004
                       7     1737000   37893.839  .5997354364626661 10190 2006
                       7      597000 39658.37385  .6105674760184742 10190 2007
                       7     2538000  40105.1103  .5703196082600038 10190 2008
                       7     3301000 41636.49607  .5591670246824842 10190 2009
                       7     1701321 42809.92706  .6919253554413991 10190 2010
                       7     2404046 44429.55951  .7410429787785415 10190 2011
                       8        1000 22405.57233 1.0623409739943255 10210 1995
                       8       74000 39658.37385  .6105674760184742 10210 2007
                       9        1000 25671.58245 1.1054380445127585 10310 1998
                      10        6625 42809.92706  .6919253554413991 10511 2010
                      11        6000 18165.37749 1.2927237591260599 10600 1991
                      11        3000   19136.159 1.1468820265633959 10600 1992
                      11        3000 20162.39481  1.124279752837919 10600 1993
                      11           0 21397.51238 1.1864691485595933 10600 1994
                      11           0 22405.57233 1.0623409739943255 10600 1995
                      11           0 23268.40581 1.1775705018011895 10600 1996
                      11        3460 24442.26533 1.2869835037875952 10600 1997
                      11        6531 27121.29636  .6053634455274293 10600 1999
                      11           0 28304.65674   .627718194674252 10600 2000
                      11        9000 29561.39887  .5774845053031988 10600 2001
                      12           0 39658.37385  .6105674760184742 10611 2007
                      13           0 47232.62912  .6771114242130912 10613 2015
                      14           0 30800.45213  .5745846697624504 10619 2002
                      14        1000 32352.94183  .5733444482815195 10619 2003
                      14        1000 33962.01514   .591226453157913 10619 2004
                      14        1000 35642.41871  .6138347163705139 10619 2005
                      14           0   37893.839  .5997354364626661 10619 2006
                      14           0 39658.37385  .6105674760184742 10619 2007
                      14        1000  40105.1103  .5703196082600038 10619 2008
                      14           0 41636.49607  .5591670246824842 10619 2009
                      14           0 42809.92706  .6919253554413991 10619 2010
                      14         278 44429.55951  .7410429787785415 10619 2011
                      14           0 43883.37889   .805899036870938 10619 2012
                      14           0 47761.90126  .7268910950231656 10619 2013
                      14        1785 47603.88088  .6785227182172638 10619 2014
                      14       29185 47232.62912  .6771114242130912 10619 2015
                      14       72806  50150.6522  .6715819582328011 10619 2016
                      end
                      
                      
                      frame create myresults
                      frame create holding
                      tempfile holding
                      local sectorname
                      xtset id year
                      local where 1
                      levelsof HSspecific, local(sectors)
                      foreach sector of local sectors{
                          capture{
                              regress d.tradevalue_ex d.GDP_CAP d.EXCH if HSspecific==`sector', robust
                              mat res= (r(table)[1..6, 1..2])'
                              frame holding{
                                  clear
                                  set obs 2
                                  svmat res
                                  save `holding', replace
                               }
                              frame myresults{
                                  append using `holding'
                                  cap gen sector= "`sector'" in `where'    
                                  replace sector= "GDP CAP sector `sector'" in `where'
                                  local ++where
                                  replace sector= "EXCH sector `sector'" in `where'
                                  local ++where
                              }
                          }
                      }
                      frame myresults{
                          order sector
                          rename  (res1- res6)  (b se t pvalue ll ul)
                      }
                      frame drop holding 
                      frame myresults: browse
                      Res.:

                      Code:
                      . frame myresults: l, sep(0)
                      
                           +--------------------------------------------------------------------------------------------+
                           |               sector           b         se           t     pvalue          ll          ul |
                           |--------------------------------------------------------------------------------------------|
                        1. |     GDP CAP sector 0   -36067.21   241201.7   -.1495314    .882632   -539205.1    467070.6 |
                        2. |        EXCH sector 0    1.12e+09   7.55e+08    1.477126   .1552161   -4.60e+08    2.69e+09 |
                        3. | GDP CAP sector 10110   -.8724005    10.5599   -.0826145   .9381271   -30.19138    28.44658 |
                        4. |    EXCH sector 10110   -307792.3   85032.23   -3.619713   .0223629   -543879.6   -71704.95 |
                        5. | GDP CAP sector 10119    94.80948   61.51299    1.541292   .1671467   -50.64561    240.2646 |
                        6. |    EXCH sector 10119    81944.82   57705.38    1.420055   .1985601   -54506.71    218396.4 |
                        7. | GDP CAP sector 10129    400.9626   238.9179    1.678244   .1918921   -359.3808    1161.306 |
                        8. |    EXCH sector 10129    1.02e+07   1.06e+07    .9666651    .405017   -2.34e+07    4.38e+07 |
                        9. | GDP CAP sector 10190   -1026.625   547.7088   -1.874399   .1341469   -2547.308    494.0586 |
                       10. |    EXCH sector 10190   -1.43e+07    3869163   -3.690321   .0210128   -2.50e+07    -3535937 |
                       11. | GDP CAP sector 10600    7.943155   15.40084    .5157612    .628009   -31.64596    47.53227 |
                       12. |    EXCH sector 10600   -1240.252   13884.85   -.0893241    .932292    -36932.4     34451.9 |
                       13. | GDP CAP sector 10619    .4996543   4.396595    .1136458   .9115663   -9.177186    10.17649 |
                       14. |    EXCH sector 10619   -22110.94   35226.43   -.6276805   .5430236    -99643.8    55421.91 |
                           +--------------------------------------------------------------------------------------------+
                      Last edited by Andrew Musau; 04 Feb 2022, 06:30.

                      Comment


                      • #12
                        It works! Thank you so much for your kind help

                        Comment


                        • #13
                          Few days ago I wanted obtain fixed effects regression coeffcients and created the log variables. However, I couldn#t obtain the results anymore. After trying and trying I completely got stuck with it.
                          Res.:
                          Code:
                          foreach sector of local sectors{
                            2.     capture{
                            3.         xtreg log_exp log_GDP log_EXCH if HSspecific==`sector
                          > ', fe
                            4.         mat res= (r(table)[1..6, 1..2])'
                            5.         frame holding{
                            6.             clear
                            7.             set obs 2
                            8.             svmat res
                            9.             save `holding', replace
                           10.          }
                           11.         frame myresults{
                           12.             append using `holding'
                           13.             cap gen sector= "`sector'" in `where'    
                           14.             replace sector= "GDP CAP sector `sector'" in `whe
                          > re'
                           15.             local ++where
                           16.             replace sector= "EXCH sector `sector'" in `where'
                           17.             local ++where
                           18.         }
                           19.     }
                           20. }
                          
                          . frame myresults{
                          .     order sector
                          no variables defined
                          r(111);
                          .     rename  (res1- res6)  (b se t pvalue ll ul)
                          . }
                          I checked the variables few times and I didn't have any typo. I run the same code you sent me and I have the same mistake, what is bizzare to me since I got the results previously. I tried and modified the loop command I found on the Internet so that my results would be store into Excel but it doesn#t work as well.
                          Code:
                          levelsof HSspecific, local(sectors)
                          
                          putexcel set "Table1", replace
                          putexcel A1 = "Sector"    
                          putexcel B1 = "N"    
                          putexcel C1 = "Slope of log GDP"    
                          putexcel D1 = "SE of log GDP"    
                          putexcel E1 = "t-stat of log GDP"    
                          putexcel F1 = "p-value of log GDP"    
                          putexcel G1 = "Slope of log_EXCH"    
                          putexcel H1 = "SE of log_EXCH"    
                          putexcel I1 = "t-stat of log_EXCH"    
                          putexcel J1 = "p-value of log_EXCH"    
                          putexcel K1 = "R2 of the model"
                          
                          local i=2
                          foreach sector of local sectors{
                              capture{
                                  
                                  di "For sector `sector'"
                                  xtreg log_exp log_GDP log_EXCH eu cm_border if HSspecific==`sector', fe
                                  
                                  local obs = e(N)
                                  local R2 = e(r2)
                                  local slope1 = _b[log_GDP]
                                  local se1 = _se[log_GDP]
                                  local t1 = _b[log_GDP]/_se[log_GDP]
                                  local p1 = 2*ttail(e(df_r), abs(`t1'))
                                  local slope2 = _b[log_EXCH]
                                  local se2 = _se[log_EXCH]
                                  local t2 = _b[log_EXCH]/_se[log_EXCH]
                                  local p2 = 2*ttail(e(df_r), abs(`t2'))
                          
                                  putexcel A`i' = `sector'    
                                  putexcel B`i' = "`obs'"    
                                  putexcel C`i' = "`slope1'"    
                                  putexcel D`i' = "`se1'"    
                                  putexcel E`i' = "`t1'"    
                                  putexcel F`i' = "`p1'"    
                                  putexcel G`i' = "`slope2'"    
                                  putexcel H`i' = "`se2'"    
                                  putexcel I`i' = "`t2'"    
                                  putexcel J`i' = "`p2'"    
                                  putexcel K`i' = "`R2'"    
                                  local i = `i' + 1
                                  }
                          }
                          Could you take a look again as an experience person at my data and see what I'm doing wrong? I have no idea why it yieldied the results on Monday and today I'm getting the error message
                          Code:
                          * Example generated by -dataex-. To install: ssc install dataex
                          clear
                          input float(log_exp log_GDP log_EXCH id) int year long HSspecific
                           21.41338  9.807273  .25675145  1 1991     0
                          21.630123  9.859335  .13704698  1 1992     0
                             21.626  9.911574   .1171426  1 1993     0
                           21.79623   9.97103   .1709818  1 1994     0
                           22.02459 10.017065  .06047494  1 1995     0
                          21.972624 10.054852   .1634534  1 1996     0
                           21.94359  10.10407   .2523011  1 1997     0
                           21.97477  10.15314  .10024168  1 1998     0
                          21.960596 10.208075 -.50192624  1 1999     0
                           21.85747 10.250782  -.4656639  1 2000     0
                           21.88538 10.294225  -.5490737  1 2001     0
                          22.030205 10.335284  -.5541078  1 2002     0
                           22.28353  10.38446 -.55626863  1 2003     0
                          22.475513 10.432998 -.52555615  1 2004     0
                           22.55476 10.481292  -.4880296  1 2005     0
                          22.654886 10.542543 -.51126665  1 2006     0
                           22.79919 10.588058  -.4933665  1 2007     0
                          23.000784  10.59926 -.56155837  1 2008     0
                           22.89651 10.636732 -.58130705  1 2009     0
                          23.066584 10.664525  -.3682772  1 2010     0
                          23.173985  10.70166 -.29969665  1 2011     0
                          23.214634  10.68929  -.2157968  1 2012     0
                          23.160517 10.773984  -.3189786  1 2013     0
                           23.06461  10.77067  -.3878373  1 2014     0
                                  . 10.335284  -.5541078  2 2002 10110
                                  .  10.38446 -.55626863  2 2003 10110
                                  . 10.432998 -.52555615  2 2004 10110
                                  . 10.481292  -.4880296  2 2005 10110
                           8.294049 10.542543 -.51126665  2 2006 10110
                                  . 10.588058  -.4933665  2 2007 10110
                          10.645425 10.636732 -.58130705  2 2009 10110
                                  . 10.664525  -.3682772  2 2010 10110
                                  .  10.70166 -.29969665  2 2011 10110
                          10.950807   9.97103   .1709818  3 1994 10111
                                  . 10.054852   .1634534  3 1996 10111
                                  .  10.10407   .2523011  3 1997 10111
                                  . 10.208075 -.50192624  3 1999 10111
                                  . 10.294225  -.5490737  3 2001 10111
                           10.83958  9.807273  .25675145  4 1991 10119
                                  .  9.859335  .13704698  4 1992 10119
                                  .  9.911574   .1171426  4 1993 10119
                                  .   9.97103   .1709818  4 1994 10119
                                  . 10.017065  .06047494  4 1995 10119
                                  . 10.054852   .1634534  4 1996 10119
                                  .  10.10407   .2523011  4 1997 10119
                                  .  10.15314  .10024168  4 1998 10119
                                  . 10.208075 -.50192624  4 1999 10119
                          11.066638 10.250782  -.4656639  4 2000 10119
                          11.198215 10.294225  -.5490737  4 2001 10119
                                  .  10.68929  -.2157968  5 2012 10121
                                  .  10.77067  -.3878373  5 2014 10121
                                  . 10.822786  -.3981192  5 2016 10121
                                  . 10.833665  -.3879531  5 2017 10121
                          15.227152  10.68929  -.2157968  6 2012 10129
                          15.211052 10.773984  -.3189786  6 2013 10129
                          14.995152  10.77067  -.3878373  6 2014 10129
                          14.288353  10.76284  -.3899194  6 2015 10129
                          14.704036 10.822786  -.3981192  6 2016 10129
                          14.532348 10.833665  -.3879531  6 2017 10129
                          13.927883 10.886076   -.457807  6 2018 10129
                          10.985292 10.335284  -.5541078  7 2002 10190
                           12.20106  10.38446 -.55626863  7 2003 10190
                           10.89674 10.432998 -.52555615  7 2004 10190
                           14.36767 10.542543 -.51126665  7 2006 10190
                          13.299672 10.588058  -.4933665  7 2007 10190
                          14.746887  10.59926 -.56155837  7 2008 10190
                          15.009736 10.636732 -.58130705  7 2009 10190
                          14.346915 10.664525  -.3682772  7 2010 10190
                          14.692664  10.70166 -.29969665  7 2011 10190
                           6.907755 10.017065  .06047494  8 1995 10210
                           11.21182 10.588058  -.4933665  8 2007 10210
                           6.907755  10.15314  .10024168  9 1998 10310
                           8.798606 10.664525  -.3682772 10 2010 10511
                           8.699514  9.807273  .25675145 11 1991 10600
                           8.006368  9.859335  .13704698 11 1992 10600
                           8.006368  9.911574   .1171426 11 1993 10600
                                  .   9.97103   .1709818 11 1994 10600
                                  . 10.017065  .06047494 11 1995 10600
                                  . 10.054852   .1634534 11 1996 10600
                           8.149024  10.10407   .2523011 11 1997 10600
                           8.784315 10.208075 -.50192624 11 1999 10600
                                  . 10.250782  -.4656639 11 2000 10600
                          9.1049795 10.294225  -.5490737 11 2001 10600
                                  . 10.588058  -.4933665 12 2007 10611
                                  .  10.76284  -.3899194 13 2015 10613
                                  . 10.335284  -.5541078 14 2002 10619
                           6.907755  10.38446 -.55626863 14 2003 10619
                           6.907755 10.432998 -.52555615 14 2004 10619
                           6.907755 10.481292  -.4880296 14 2005 10619
                                  . 10.542543 -.51126665 14 2006 10619
                                  . 10.588058  -.4933665 14 2007 10619
                           6.907755  10.59926 -.56155837 14 2008 10619
                                  . 10.636732 -.58130705 14 2009 10619
                                  . 10.664525  -.3682772 14 2010 10619
                           5.627621  10.70166 -.29969665 14 2011 10619
                                  .  10.68929  -.2157968 14 2012 10619
                                  . 10.773984  -.3189786 14 2013 10619
                           7.487174  10.77067  -.3878373 14 2014 10619
                           10.28141  10.76284  -.3899194 14 2015 10619
                          11.195554 10.822786  -.3981192 14 2016 10619
                          end

                          Comment


                          • #14
                            Add -noisily- to your capture command. Among the errors, you have not xtset your data plus you lack some variables.

                            Code:
                            frame create myresults
                            frame create holding
                            tempfile holding
                            local sectorname
                            xtset id year
                            local where 1
                            levelsof HSspecific, local(sectors)
                            xtset HSspecific year
                            foreach sector of local sectors{
                                capture noisily{
                                    di "For sector `sector'"
                                    xtreg log_exp log_GDP log_EXCH eu cm_border if HSspecific==`sector', fe 
                                    mat res= (r(table)[1..6, 1..2])'
                                    frame holding{
                                        clear
                                        set obs 2
                                        svmat res
                                        save `holding', replace
                                     }
                                    frame myresults{
                                        append using `holding'
                                        cap gen sector= "`sector'" in `where'    
                                        replace sector= "GDP CAP sector `sector'" in `where'
                                        local ++where
                                        replace sector= "EXCH sector `sector'" in `where'
                                        local ++where
                                    }
                                }
                            }
                            frame myresults{
                                order sector
                                rename  (res1- res6)  (b se t pvalue ll ul)
                            }
                            frame drop holding 
                            frame myresults: browse
                            Res,:

                            Code:
                            . foreach sector of local sectors{
                              2. 
                            .     capture noisily{
                              3. 
                            .         di "For sector `sector'"
                              4. 
                            .         xtreg log_exp log_GDP log_EXCH eu cm_border if HSspecific==`sector', fe
                              5. 
                            .         mat res= (r(table)[1..6, 1..2])'
                              6. 
                            .         frame holding{
                              7. 
                            .             clear
                              8. 
                            .             set obs 2
                              9. 
                            .             svmat res
                             10. 
                            .             save `holding', replace
                             11. 
                            .          }
                             12. 
                            .         frame myresults{
                             13. 
                            .             append using `holding'
                             14. 
                            .             cap gen sector= "`sector'" in `where'    
                             15. 
                            .             replace sector= "GDP CAP sector `sector'" in `where'
                             16. 
                            .             local ++where
                             17. 
                            .             replace sector= "EXCH sector `sector'" in `where'
                             18. 
                            .             local ++where
                             19. 
                            .         }
                             20. 
                            .     }
                             21. 
                            . }
                            For sector 0
                            variable eu not found
                            For sector 10110
                            variable eu not found
                            For sector 10111
                            variable eu not found
                            For sector 10119
                            variable eu not found
                            For sector 10121
                            variable eu not found
                            For sector 10129
                            variable eu not found
                            For sector 10190
                            variable eu not found
                            For sector 10210
                            variable eu not found
                            For sector 10310
                            variable eu not found
                            For sector 10511
                            variable eu not found
                            For sector 10600
                            variable eu not found
                            For sector 10611
                            variable eu not found
                            For sector 10613
                            variable eu not found
                            For sector 10619
                            variable eu not found
                            
                            . 
                            . frame myresults{
                            . 
                            .     order sector
                            no variables defined
                            r(111);
                            . 
                            .     rename  (res1- res6)  (b se t pvalue ll ul)
                            . 
                            . }
                            r(111);
                            
                            . 
                            . frame drop holding 
                            
                            . 
                            . frame myresults: browse
                            
                            .

                            Comment


                            • #15
                              I got the results! Thank you so much

                              Comment

                              Working...
                              X