Announcement

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

  • Using if command for limiting sample in panel data

    Hi all..

    to begin with, I have a panel data of 24 companies with annual data from 2005-2014.

    I have variable revenue and some other variable such as equity, age of the company, GDP, inflation etc.

    however right now I want to try to limit my sample into only companies that the revenue in 2014 less than certain value (lets say 1 million USD for instance). can I perform that directly using if command?




    regards.


  • #2
    Dono:
    you may want to try something along the lines of the following toy-example:
    Code:
    . use http://www.stata-press.com/data/r13/nlswork.dta
    (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
    
    . xtreg ln_wage age if age<20, fe
    
    Fixed-effects (within) regression               Number of obs      =      1664
    Group variable: idcode                          Number of groups   =      1161
    
    R-sq:  within  = 0.1634                         Obs per group: min =         1
           between = 0.0197                                        avg =       1.4
           overall = 0.0444                                        max =         4
    
                                                    F(1,502)           =     98.08
    corr(u_i, Xb)  = -0.0341                        Prob > F           =    0.0000
    
    ------------------------------------------------------------------------------
         ln_wage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             age |   .1261451   .0127375     9.90   0.000     .1011197    .1511704
           _cons |  -1.016684   .2354667    -4.32   0.000    -1.479306   -.5540627
    -------------+----------------------------------------------------------------
         sigma_u |  .35460962
         sigma_e |  .24365475
             rho |  .67929429   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    F test that all u_i=0:     F(1160, 502) =     2.81           Prob > F = 0.0000
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      You can't specify it directly, but calculate the filter before:


      ​ bys company : egen filter=max(revenue=<1000000 & year==2014)

      Comment


      • #4
        Dono:
        Oded's solution is smarter than mine.
        However, you can include more than one -if- qualifiers in the same Stata code:
        Code:
        . use http://www.stata-press.com/data/r13/nlswork.dta
        (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
        
        . xtreg ln_wage age if age<20 & year<72, fe
        
        Fixed-effects (within) regression               Number of obs      =      1312
        Group variable: idcode                          Number of groups   =       972
        
        R-sq:  within  = 0.1668                         Obs per group: min =         1
               between = 0.0358                                        avg =       1.3
               overall = 0.0556                                        max =         4
        
                                                        F(1,339)           =     67.87
        corr(u_i, Xb)  = -0.0387                        Prob > F           =    0.0000
        
        ------------------------------------------------------------------------------
             ln_wage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                 age |   .1332124   .0161697     8.24   0.000     .1014067     .165018
               _cons |  -1.135587   .2978147    -3.81   0.000    -1.721384    -.549789
        -------------+----------------------------------------------------------------
             sigma_u |   .3517306
             sigma_e |  .24919247
                 rho |  .66580672   (fraction of variance due to u_i)
        ------------------------------------------------------------------------------
        F test that all u_i=0:     F(971, 339) =     2.53            Prob > F = 0.0000
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Hi Carlo and Dono ,
          Carlo Lazzaro, my solution isn't smarter than yours, but different. Since Dono's data is probably panel with years nested within companies, and he ask to limit companies based on value in a specific year, the code I proposed will omit the whole company from the panel (including the years before 2014). Your code is different since it will drop some years from the panel but will keep the company with earlier years, this might cause an unbalanced panel. I think this is not what Dono ask for.

          Comment


          • #6
            Thx a lot Oded, it really works, however I dont really get it why the new variable contains only value of 1 and 0. I thought that since max will return the highest value, so it will just return the value of revenue in 2014 if the revenue is less than 1000000.


            @Carlo: yeah I also have thought about using more than if, but if I use

            xtreg revenue equity if revenue < 1000 and year == 14, fe

            then wouldnt stata would exclude observation other than in 2014?




            Comment


            • #7
              http://www.stata.com/support/faqs/da...ble-recording/ may help here.

              Comment

              Working...
              X