Announcement

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

  • #16
    Meghna:
    -xtset-ting data with -timevar- is mandatory if you plan to use, say, lags and leads. If time series commands are not part of your research strategy, you can safely skip -xtset-ting with -timevar-, as you can see from the following toy-example:
    Code:
    . use "http://www.stata-press.com/data/r15/nlswork.dta"
    (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
    
    . xtset idcode
           panel variable:  idcode (unbalanced)
    
    . xtreg ln_wage age i.year
    
    Random-effects GLS regression                   Number of obs     =     28,510
    Group variable: idcode                          Number of groups  =      4,710
    
    R-sq:                                           Obs per group:
         within  = 0.1060                                         min =          1
         between = 0.0918                                         avg =        6.1
         overall = 0.0807                                         max =         15
    
                                                    Wald chi2(15)     =    3253.70
    corr(u_i, X)   = 0 (assumed)                    Prob > chi2       =     0.0000
    
    ------------------------------------------------------------------------------
         ln_wage |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             age |   .0137208   .0018898     7.26   0.000     .0100169    .0174247
                 |
            year |
             69  |   .0744312    .012506     5.95   0.000     .0499199    .0989425
             70  |   .0453659   .0120494     3.77   0.000     .0217496    .0689822
             71  |   .0819949   .0125373     6.54   0.000     .0574222    .1065676
             72  |   .0827461   .0136074     6.08   0.000      .056076    .1094162
             73  |   .0840751   .0143598     5.85   0.000     .0559304    .1122198
             75  |   .0707387   .0167492     4.22   0.000     .0379108    .1035665
             77  |   .1032639   .0197156     5.24   0.000      .064622    .1419059
             78  |   .1279039   .0214888     5.95   0.000     .0857866    .1700211
             80  |    .108871   .0247933     4.39   0.000      .060277     .157465
             82  |    .098831   .0280824     3.52   0.000     .0437906    .1538714
             83  |   .1127655   .0298539     3.78   0.000     .0542529    .1712781
             85  |   .1380611   .0333412     4.14   0.000     .0727135    .2034087
             87  |   .1264818   .0369222     3.43   0.001     .0541156     .198848
             88  |   .1640382   .0393563     4.17   0.000     .0869012    .2411752
                 |
           _cons |   1.162473     .03784    30.72   0.000     1.088308    1.236638
    -------------+----------------------------------------------------------------
         sigma_u |  .36664367
         sigma_e |  .30300411
             rho |  .59418375   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    
    . xtset idcode year
           panel variable:  idcode (unbalanced)
            time variable:  year, 68 to 88, but with gaps
                    delta:  1 unit
    
    . xtreg ln_wage age i.year
    
    Random-effects GLS regression                   Number of obs     =     28,510
    Group variable: idcode                          Number of groups  =      4,710
    
    R-sq:                                           Obs per group:
         within  = 0.1060                                         min =          1
         between = 0.0918                                         avg =        6.1
         overall = 0.0807                                         max =         15
    
                                                    Wald chi2(15)     =    3253.70
    corr(u_i, X)   = 0 (assumed)                    Prob > chi2       =     0.0000
    
    ------------------------------------------------------------------------------
         ln_wage |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             age |   .0137208   .0018898     7.26   0.000     .0100169    .0174247
                 |
            year |
             69  |   .0744312    .012506     5.95   0.000     .0499199    .0989425
             70  |   .0453659   .0120494     3.77   0.000     .0217496    .0689822
             71  |   .0819949   .0125373     6.54   0.000     .0574222    .1065676
             72  |   .0827461   .0136074     6.08   0.000      .056076    .1094162
             73  |   .0840751   .0143598     5.85   0.000     .0559304    .1122198
             75  |   .0707387   .0167492     4.22   0.000     .0379108    .1035665
             77  |   .1032639   .0197156     5.24   0.000      .064622    .1419059
             78  |   .1279039   .0214888     5.95   0.000     .0857866    .1700211
             80  |    .108871   .0247933     4.39   0.000      .060277     .157465
             82  |    .098831   .0280824     3.52   0.000     .0437906    .1538714
             83  |   .1127655   .0298539     3.78   0.000     .0542529    .1712781
             85  |   .1380611   .0333412     4.14   0.000     .0727135    .2034087
             87  |   .1264818   .0369222     3.43   0.001     .0541156     .198848
             88  |   .1640382   .0393563     4.17   0.000     .0869012    .2411752
                 |
           _cons |   1.162473     .03784    30.72   0.000     1.088308    1.236638
    -------------+----------------------------------------------------------------
         sigma_u |  .36664367
         sigma_e |  .30300411
             rho |  .59418375   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #17
      Thanks Carlo, I get your point...I think this might work

      Comment


      • #18
        I have often seen the claim that there are no duplicates despite this error message and hitherto I have always believed Stata, The FAQ cited in #12 arose because the second author made such a claim and then found that they were wrong. In turn please make explicit the results of

        Code:
        xtset state year
        duplicates report state year
        Please back up, read the FAQ Advice, especially Section 12, and show us exact results, not a claim that nothing is working.

        It seems however that you have household data. If so, my guess is that you have many households within each state-year combination, in which case declaring states as panels just won't work except as Carlo suggests.
        Last edited by Nick Cox; 13 Jun 2018, 02:19.

        Comment


        • #19
          Originally posted by Nick Cox View Post
          I have often seen the claim that there are no duplicates despite this error message and hitherto I have always believed Stata, The FAQ cited in #12 arose because the second author made such a claim and then found that they were wrong. In turn please make explicit the results of

          Code:
          xtset state year
          duplicates report state year
          Please back up, read the FAQ Advice, especially Section 12, and show us exact results, not a claim that nothing is working.

          It seems however that you have household data. If so, my guess is that you have many households within each state-year combination, in which case declaring states as panels just won't work except as Carlo suggests.
          Yes it a household data, so I do have many households within each state-year combination. I will post my exact results in the next post.

          Thanks,
          Meghna

          Comment


          • #20
            Here you go...

            Code:
            xtset state year
            repeated time values within panel
            r(451);
            
            . duplicates report state year
            
            Duplicates in terms of state year
            
            --------------------------------------
               copies | observations       surplus
            ----------+---------------------------
                 1515 |         1515          1514
                 2933 |         2933          2932
                 3023 |         3023          3022
                 4535 |         4535          4534
                 4759 |         4759          4758
                 6086 |         6086          6085
                 6435 |         6435          6434
                 7318 |         7318          7317
                 8044 |         8044          8043
                 8110 |         8110          8109
                 9121 |         9121          9120
                10626 |        10626         10625
                10666 |        10666         10665
                11840 |        11840         11839
                13009 |        13009         13008
                13210 |        13210         13209
                13576 |        13576         13575
                15182 |        15182         15181
                15200 |        15200         15199
                15790 |        15790         15789
                16128 |        16128         16127
                16505 |        16505         16504
                17716 |        17716         17715
                19163 |        19163         19162
                20402 |        40804         40802
                21689 |        21689         21688
                24182 |        24182         24181
                24433 |        24433         24432
                26581 |        26581         26580
                29785 |        29785         29784
                32038 |        32038         32037
                39739 |        39739         39738
                41392 |        41392         41391
                41594 |        41594         41593
                46648 |        46648         46647
                50891 |        50891         50890
                51973 |        51973         51972
                54173 |        54173         54172
                57154 |        57154         57153
                57287 |        57287         57286
                58628 |        58628         58627
                74200 |        74200         74199
                86977 |        86977         86976
                91681 |        91681         91680
                94461 |        94461         94460
               105305 |       105305        105304
               107556 |       107556        107555
               116077 |       116077        116076
               120694 |       120694        120693
               120721 |       120721        120720
               124368 |       124368        124367
               170745 |       170745        170744
               181684 |       181684        181683
               192508 |       192508        192507
               218979 |       218979        218978
               234333 |       234333        234332
            --------------------------------------

            Code:
            duplicates report
            
            Duplicates in terms of all variables
            
            --------------------------------------
               copies | observations       surplus
            ----------+---------------------------
                    1 |      2989770             0
            --------------------------------------
            Code:
            duplicates report state hhid_code year
            
            Duplicates in terms of state hhid_code year
            
            --------------------------------------
               copies | observations       surplus
            ----------+---------------------------
                    1 |         1721             0
                    2 |         7116          3558
                    3 |        14910          9940
                    4 |        22576         16932
                    5 |        25915         20732
                    6 |        27186         22655
                    7 |        27223         23334
                    8 |        26592         23268
                    9 |        24444         21728
                   10 |        20220         18198
                   11 |        18139         16490
                   12 |        16764         15367
                   13 |        15431         14244
                   14 |        15372         14274
                   15 |        15240         14224
                   16 |        15696         14715
                   17 |        15606         14688
                   18 |        19008         17952
                   19 |        21736         20592
                   20 |        23600         22420
                   21 |        27153         25860
                   22 |        28116         26838
                   23 |        29831         28534
                   24 |        28824         27623
                   25 |        29700         28512
                   26 |        27144         26100
                   27 |        26676         25688
                   28 |        25060         24165
                   29 |        24766         23912
                   30 |        21750         21025
                   31 |        24335         23550
                   32 |        23584         22847
                   33 |        26499         25696
                   34 |        28526         27687
                   35 |        32725         31790
                   36 |        38844         37765
                   37 |        41921         40788
                   38 |        46588         45362
                   39 |        51129         49818
                   40 |        52560         51246
                   41 |        58056         56640
                   42 |        60396         58958
                   43 |        61146         59724
                   44 |        63096         61662
                   45 |        64710         63272
                   46 |        61824         60480
                   47 |        58280         57040
                   48 |        57744         56541
                   49 |        52969         51888
                   50 |        50450         49441
                   51 |        45798         44900
                   52 |        40144         39372
                   53 |        37100         36400
                   54 |        33804         33178
                   55 |        29645         29106
                   56 |        26544         26070
                   57 |        23655         23240
                   58 |        22040         21660
                   59 |        20591         20242
                   60 |        19740         19411
                   61 |        16470         16200
                   62 |        14942         14701
                   63 |        14112         13888
                   64 |        13120         12915
                   65 |        13455         13248
                   66 |        15048         14820
                   67 |        14070         13860
                   68 |        17272         17018
                   69 |        15801         15572
                   70 |        18410         18147
                   71 |        16898         16660
                   72 |        17712         17466
                   73 |        18980         18720
                   74 |        19758         19491
                   75 |        21600         21312
                   76 |        20824         20550
                   77 |        20559         20292
                   78 |        21996         21714
                   79 |        22199         21918
                   80 |        24880         24569
                   81 |        23166         22880
                   82 |        23370         23085
                   83 |        24070         23780
                   84 |        26460         26145
                   85 |        28390         28056
                   86 |        25198         24905
                   87 |        24969         24682
                   88 |        24728         24447
                   89 |        24742         24464
                   90 |        26460         26166
                   91 |        22659         22410
                   92 |        24840         24570
                   93 |        21855         21620
                   94 |        20962         20739
                   95 |        18430         18236
                   96 |        18528         18335
                   97 |        17654         17472
                   98 |        17150         16975
                   99 |        18315         18130
                  100 |        15500         15345
                  101 |        15352         15200
                  102 |        12750         12625
                  103 |        11948         11832
                  104 |        10712         10609
                  105 |         9135          9048
                  106 |        10918         10815
                  107 |         8239          8162
                  108 |         9612          9523
                  109 |         9810          9720
                  110 |         6820          6758
                  111 |         8436          8360
                  112 |         7280          7215
                  113 |         6893          6832
                  114 |         6954          6893
                  115 |         6095          6042
                  116 |         5684          5635
                  117 |         3861          3828
                  118 |         5192          5148
                  119 |         2856          2832
                  120 |         2880          2856
                  121 |         4356          4320
                  122 |         3416          3388
                  123 |         3567          3538
                  124 |         3100          3075
                  125 |         2750          2728
                  126 |         3780          3750
                  127 |         3175          3150
                  128 |         1920          1905
                  129 |         2967          2944
                  130 |         3510          3483
                  131 |         3013          2990
                  132 |         2640          2620
                  133 |         2660          2640
                  134 |         3216          3192
                  135 |         2295          2278
                  136 |         2040          2025
                  137 |         2877          2856
                  138 |         3312          3288
                  139 |         2363          2346
                  140 |         1820          1807
                  141 |         2397          2380
                  142 |         1562          1551
                  143 |         2145          2130
                  144 |         1440          1430
                  145 |         1450          1440
                  146 |         1168          1160
                  147 |         1323          1314
                  148 |         1184          1176
                  149 |         1341          1332
                  150 |         1800          1788
                  151 |         1057          1050
                  152 |         1520          1510
                  153 |         1377          1368
                  154 |         1540          1530
                  155 |         1550          1540
                  156 |         2028          2015
                  157 |         2198          2184
                  158 |          948           942
                  159 |         1272          1264
                  160 |         1120          1113
                  161 |         2415          2400
                  162 |          972           966
                  163 |         1630          1620
                  164 |         1312          1304
                  165 |          990           984
                  166 |          830           825
                  167 |         1670          1660
                  168 |         1008          1002
                  169 |          845           840
                  170 |         1020          1014
                  171 |          855           850
                  172 |          688           684
                  173 |          346           344
                  174 |          696           692
                  175 |          525           522
                  176 |          880           875
                  177 |          354           352
                  178 |          178           177
                  179 |          537           534
                  180 |          180           179
                  181 |          543           540
                  182 |          364           362
                  183 |          366           364
                  184 |          368           366
                  185 |          925           920
                  186 |          186           185
                  187 |          374           372
                  188 |          188           187
                  189 |          567           564
                  190 |          190           189
                  191 |          573           570
                  192 |          192           191
                  193 |          193           192
                  194 |          388           386
                  195 |          195           194
                  196 |          196           195
                  197 |          591           588
                  198 |          594           591
                  199 |          398           396
                  201 |          402           400
                  202 |          202           201
                  203 |          406           404
                  204 |          204           203
                  205 |         1025          1020
                  207 |          207           206
                  208 |          208           207
                  209 |          209           208
                  210 |          210           209
                  211 |          422           420
                  214 |          214           213
                  215 |          645           642
                  216 |          216           215
                  217 |          434           432
                  218 |          436           434
                  219 |          219           218
                  221 |          221           220
                  222 |          444           442
                  226 |          226           225
                  229 |          229           228
                  231 |          231           230
                  235 |          470           468
                  237 |          237           236
                  240 |          240           239
                  244 |          244           243
                  245 |          245           244
                  248 |          248           247
                  249 |          249           248
                  251 |          251           250
                  256 |          512           510
                  273 |          273           272
                  335 |          335           334
            --------------------------------------
            
            .

            Code:
             duplicates drop hhid_code state year, force
            
            Duplicates in terms of hhid_code state year
            
            (2888762 observations deleted)
            Code:
            duplicates report
            
            Duplicates in terms of all variables
            
            --------------------------------------
               copies | observations       surplus
            ----------+---------------------------
                    1 |       101008             0
            Code:
            duplicates report state hhid_code year
            
            Duplicates in terms of state hhid_code year
            
            --------------------------------------
               copies | observations       surplus
            ----------+---------------------------
                    1 |       101008             0
            --------------------------------------
            Code:
            duplicates list hhid_code state year , sepby(hhid_code)
            
            Duplicates in terms of hhid_code state year
            
            (0 observations are duplicates)
            Code:
            xtset state year
            repeated time values within panel
            r(451);
            Even if I tried removing all the duplicates in terms of hhid_code state and year (although it is a household data and should have duplicates in terms of household id), I am still gfetting the same error message!!

            Regards,
            Meghna

            Comment


            • #21
              Thanks for the detailed report. Why are you still surprised at the error message, as the results confirm the guesses suggested to you? For

              Code:
              xtset state year 
              to work each state, year combination can occur at most once. As you have enormous duplication, whereby many households exist in every state, your only scope for using xtset is as Carlo suggested and I underlined in terms of declaring a panel identifier alone. Alternatively, what is key is why you think that xtset statement matches your analysis goals: it certainly doesn't match your data.

              Comment


              • #22
                Anybody following up on this with more complex panel data may benefit from this discussion:
                https://www.statalist.org/forums/for...s-within-panel
                Last edited by Jarsh Landbarg; 18 Apr 2021, 09:00.

                Comment

                Working...
                X