Announcement

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

  • if condition in xtreg

    Hello, everyone!

    I do not understund why the output shows me minimum number of observation that equels 5, however, I establish condition consider only those where it is more that 10. COuld enyone help me? I am using xtreg in Stata 13.1.

    Here I create variable that counts observations per group (which is country)

    Code:
    egen gdp_count = count(l_gdp_percap), by(ISO3N)
    This is the model I'd like to estimete

    Code:
    xtreg l_gdp_percap ib1.reg_magnr  L(1/3).l_gdp_percap  ib0.persol2  i.decade if gdp_count>10, fe cl(ISO3N)

    PHP Code:
    Fixed-effects (withinregression               Number of obs      =      3409
    Group variable
    ISO3N                           Number of groups   =       117

    R
    -sq:  within  0.9654                         Obs per groupmin =         2
           between 
    0.9997                                        avg =      29.1
           overall 
    0.9968                                        max =        50

                                                    F
    (14,116)          =   3000.34
    corr
    (u_iXb)  = 0.8411                         Prob F           =    0.0000

                                     
    (StdErradjusted for 117 clusters in ISO3N)
    -------------------------------------------------------------------------------
                  |               
    Robust
     l_gdp_percap 
    |      Coef.   StdErr.      t    P>|t|     [95ConfInterval]
    --------------+----------------------------------------------------------------
        
    reg_magnr |
        
    Military  |  -.0243957   .0104707    -2.33   0.022    -.0451341   -.0036572
          Morchy  
    |   .0055622   .0160169     0.35   0.729    -.0261613    .0372857
      Multiparty  
    |  -.0165441    .009361    -1.77   0.080    -.0350848    .0019965
    Single Party  
    |  -.0172222   .0124459    -1.38   0.169    -.0418729    .0074285
                  
    |
     
    l_gdp_percap |
              
    L1. |   1.209961   .0800573    15.11   0.000     1.051398    1.368525
              L2
    . |  -.1723034   .0931483    -1.85   0.067    -.3567953    .0121885
              L3
    . |  -.0700679   .0287383    -2.44   0.016    -.1269876   -.0131481
                  
    |
          
    persol2 |
               
    1  |   .0149075   .0070386     2.12   0.036     .0009666    .0288484
               2  
    |   .0141714   .0089652     1.58   0.117    -.0035853    .0319281
                  
    |
           
    decade |
            
    1970  |   .0029361   .0036517     0.80   0.423    -.0042966    .0101689
            1980  
    |  -.0088728   .0044202    -2.01   0.047    -.0176276   -.0001179
            1990  
    |  -.0090631   .0050484    -1.80   0.075    -.0190621    .0009359
            2000  
    |   .0154033   .0073271     2.10   0.038      .000891    .0299157
            2010  
    |   .0184441   .0089666     2.06   0.042     .0006846    .0362035
                  
    |
            
    _cons |   .2525653   .0527426     4.79   0.000     .1481018    .3570287
    --------------+----------------------------------------------------------------
          
    sigma_u |  .04344562
          sigma_e 
    |  .06886767
              rho 
    |  .28468218   (fraction of variance due to u_i)
    -------------------------------------------------------------------------------



  • #2
    Evgenia:
    lagged variables may be an explanation of your min=2 observations.
    As an aside, if you include lagged dependent variable among predictors (as it seems from you post), your estimates will be biased. I would take a look at -xtabond-, instead.
    Last edited by Carlo Lazzaro; 07 May 2017, 11:09.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thank you, Carlo!

      I also thought about the lagged variables, but yearsterday everything worked fine!
      And the ferquences of the the dependent variable that countes observations per group (country) seem to be fine.


      PHP Code:
      ----------------------
       
      table count

        count 
      |      Freq.
      ----------+-----------
              
      |        570
             12 
      |         54
             13 
      |         54
             14 
      |         54
             15 
      |         54
             17 
      |         54
             18 
      |         54
             19 
      |        432
             20 
      |        108
             21 
      |         54
             22 
      |         54
             23 
      |         54
             24 
      |        594
             25 
      |         54
             26 
      |        108
             27 
      |        162
             28 
      |        108
             29 
      |        108
             30 
      |        108
             32 
      |         54
             33 
      |        108
             34 
      |        478
             37 
      |         54
             38 
      |         54
             39 
      |        207
             44 
      |        270
             46 
      |        162
             47 
      |         54
             48 
      |        162
             49 
      |        270
             53 
      |         54
             54 
      |      4,482
      ---------------------- 
      Thanks for advice with -xtabond-, this is the nex step, firstly I decided to check FE.
      I'm also scared that the imposibility to establish condition for number of observations will cause bad estimates using GMM (because of too many instruments, I have large T sample).

      Actually, even estimatin the model without lagged dependent variable I still cannot establish the condition.

      PHP Code:
       xtreg l_gdp_percap ib1.reg_magnr  ib0.persol2  i.decade if gdp_count>10fe cl(ISO3N)

      Fixed-effects (withinregression               Number of obs      =      3659
      Group variable
      ISO3N                           Number of groups   =       117

      R
      -sq:  within  0.2277                         Obs per groupmin =         5
             between 
      0.0061                                        avg =      31.3
             overall 
      0.0366                                        max =        53

                                                      F
      (11,116)          =     10.41
      corr
      (u_iXb)  = 0.0088                         Prob F           =    0.0000

                                       
      (StdErradjusted for 117 clusters in ISO3N)
      -------------------------------------------------------------------------------
                    |               
      Robust
       l_gdp_percap 
      |      Coef.   StdErr.      t    P>|t|     [95ConfInterval]
      --------------+----------------------------------------------------------------
          
      reg_magnr |
          
      Military  |  -.0218377   .2179559    -0.10   0.920    -.4535268    .4098514
            Morchy  
      |   .1438201   .3388362     0.42   0.672    -.5272876    .8149279
        Multiparty  
      |  -.0514717   .2193221    -0.23   0.815    -.4858668    .3829234
      Single Party  
      |   .0916895   .2368069     0.39   0.699    -.3773364    .5607154
                    
      |
            
      persol2 |
                 
      1  |   .1894304   .0975784     1.94   0.055    -.0038359    .3826967
                 2  
      |   .1638425   .1010949     1.62   0.108    -.0363886    .3640737
                    
      |
             
      decade |
              
      1970  |    .224083   .0387758     5.78   0.000     .1472826    .3008834
              1980  
      |   .2830303   .0677675     4.18   0.000     .1488082    .4172524
              1990  
      |   .3352445   .1037122     3.23   0.002     .1298295    .5406596
              2000  
      |   .6098887   .1218926     5.00   0.000      .368465    .8513124
              2010  
      |   .8137106   .1345645     6.05   0.000     .5471885    1.080233
                    
      |
              
      _cons |   6.856443    .244648    28.03   0.000     6.371887    7.340999
      --------------+----------------------------------------------------------------
            
      sigma_u |  1.2208027
            sigma_e 
      |  .33484565
                rho 
      |  .93003249   (fraction of variance due to u_i)
      ------------------------------------------------------------------------------- 
      Last edited by Evgeniya Mitrokhina; 07 May 2017, 11:09.

      Comment


      • #4
        Evgenia:
        have you checked that you were working on the same yesterday's dataset?
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Yep, I did, that was the same one, but I created the variable differently

          Code:
          egen count = total(e(sample)), by( ISO3N )
          which was wrong.

          And the today's version

          Code:
          egen gdp_count = count(l_gdp_percap), by(ISO3N)
          I want to create a variable that counts observations per country (ISO3N) for GDP (l_gdp_percap) and then use only these ones where there are more than 10 observations of the dependent variable per country.

          Comment


          • #6
            Evgenia:
            do you mean that you could have experienced the same problem yesterday had you create the count variable in the same way?
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              I ment that today I realised that count variable was constructed incorrectly, that is why today I created anotehr one, which is gdp_count and it doesn't work in regression (I theink teh second one is correct meanin that O would like to count observations per country (ISO3N) for GDP (l_gdp_percap), am I right?)

              Comment


              • #8
                Evgeniya:
                yes, the second one is correct for your research goal.
                Kind regards,
                Carlo
                (Stata 19.0)

                Comment


                • #9
                  But still it doesn't work with xtreg

                  Comment


                  • #10
                    Evgeniya, in addition to Carlo's helpful advice in #2, consider that an observation includes all entries of variables in your model and not just of the dependent variable. Stata like most other software programs employs listwise deletion i.e., an entire observation is excluded from analysis if any single value is missing. I illustrate with a simple example:

                    Code:
                    . clear
                    
                    . webuse grunfeld
                    
                    . keep if time<5 & company<4
                    (188 observations deleted)
                    
                    . replace mvalue=. if inrange(_n, 6, 7)
                    (2 real changes made, 2 to missing)
                    
                    . egen count= count(invest), by(company)
                    
                    . l, sepby(company)
                    
                         +----------------------------------------------------------+
                         | company   year   invest   mvalue   kstock   time   count |
                         |----------------------------------------------------------|
                      1. |       1   1935    317.6   3078.5      2.8      1       4 |
                      2. |       1   1936    391.8   4661.7     52.6      2       4 |
                      3. |       1   1937    410.6   5387.1    156.9      3       4 |
                      4. |       1   1938    257.7   2792.2    209.2      4       4 |
                         |----------------------------------------------------------|
                      5. |       2   1935    209.9   1362.4     53.8      1       4 |
                      6. |       2   1936    355.3        .     50.5      2       4 |
                      7. |       2   1937    469.9        .    118.1      3       4 |
                      8. |       2   1938    262.3   1801.9    260.2      4       4 |
                         |----------------------------------------------------------|
                      9. |       3   1935     33.1   1170.6     97.8      1       4 |
                     10. |       3   1936       45   2015.8    104.4      2       4 |
                     11. |       3   1937     77.2   2803.3      118      3       4 |
                     12. |       3   1938     44.6   2039.7    156.2      4       4 |
                         +----------------------------------------------------------+
                    
                    
                    
                    \\\ NOTICE THAT THE MINIMUM NOBS= 2 BELOW BECAUSE COMPANY 2 HAS 2 MISSING 
                    VALUES FOR MVALUE IN SPITE OF NO MISSING VALUE FOR THE OUTCOME INVEST 
                    
                    
                    . xtreg invest mvalue kstock, fe cl(company)
                    
                    Fixed-effects (within) regression               Number of obs     =         10
                    Group variable: company                         Number of groups  =          3
                    
                    R-sq:                                           Obs per group:
                         within  = 0.8618                                         min =          2
                         between = 0.4286                                         avg =        3.3
                         overall = 0.5674                                         max =          4
                    
                                                                    F(2,2)            =      16.88
                    corr(u_i, Xb)  = 0.3970                         Prob > F          =     0.0559
                    
                                                    (Std. Err. adjusted for 3 clusters in company)
                    ------------------------------------------------------------------------------
                                 |               Robust
                          invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                          mvalue |   .0498509   .0089992     5.54   0.031     .0111306    .0885711
                          kstock |  -.0633788   .1704306    -0.37   0.746    -.7966824    .6699247
                           _cons |   77.49927   25.62287     3.02   0.094    -32.74703    187.7456
                    -------------+----------------------------------------------------------------
                         sigma_u |   117.1291
                         sigma_e |   21.88049
                             rho |  .96628001   (fraction of variance due to u_i)
                    ------------------------------------------------------------------------------
                    
                    .

                    Comment

                    Working...
                    X