Announcement

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

  • time variable about panel data

    Hello,

    I have panel data from 2001m01 to 2020m12(2001 year, m month),but when I operate the following code:

    xtset importer ym, monthly

    it shows:
    panel variable: importer1 (strongly balanced)
    time variable: ym1, 1960m2 to 1980m1
    delta: 1 month
    I don't know why the time variable is different from my original data.

    Best wishes,

    Kendal

  • #2
    Kendal:
    as we do not know what your original data look like, it is impossible (for me, at least) to reply positively.
    From your code, you told Stata that your timevar is recorded in months.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Originally posted by Carlo Lazzaro View Post
      Kendal:
      as we do not know what your original data look like, it is impossible (for me, at least) to reply positively.
      From your code, you told Stata that your timevar is recorded in months.
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input long(ym1 importer1) str3 exporter float imports
       1 1 "USA"  19437.69
       2 1 "USA"  19689.31
       3 1 "USA"  19940.93
       4 1 "USA"  20192.55
       5 1 "USA"  20444.17
       6 1 "USA" 20695.793
       7 1 "USA"  20947.41
       8 1 "USA" 21199.033
       9 1 "USA" 21450.654
      10 1 "USA" 21702.275
      11 1 "USA" 21953.895
      12 1 "USA" 22205.516
      13 1 "USA" 22457.137
      14 1 "USA"  22957.17
      15 1 "USA"   23457.2
      16 1 "USA" 23957.227
      17 1 "USA"  24457.26
      18 1 "USA"  24957.29
      19 1 "USA"  25457.32
      20 1 "USA"  25957.35
      21 1 "USA"  26457.38
      22 1 "USA"  26957.41
      23 1 "USA"  27457.44
      24 1 "USA"  27957.47
      25 1 "USA"   28457.5
      26 1 "USA" 29011.766
      27 1 "USA"  29566.03
      28 1 "USA"   30120.3
      29 1 "USA" 30674.564
      30 1 "USA"  31228.83
      31 1 "USA" 31783.096
      32 1 "USA"  32337.36
      33 1 "USA"  32891.63
      34 1 "USA"  33445.89
      35 1 "USA" 34000.156
      36 1 "USA" 34554.426
      37 1 "USA"  35108.69
      38 1 "USA" 35533.434
      39 1 "USA"  35958.18
      40 1 "USA" 36382.926
      end
      format %tm ym1
      label values ym1 ym1
      label def ym1 1 "2001M01", modify
      label def ym1 2 "2001M02", modify
      label def ym1 3 "2001M03", modify
      label def ym1 4 "2001M04", modify
      label def ym1 5 "2001M05", modify
      label def ym1 6 "2001M06", modify
      label def ym1 7 "2001M07", modify
      label def ym1 8 "2001M08", modify
      label def ym1 9 "2001M09", modify
      label def ym1 10 "2001M10", modify
      label def ym1 11 "2001M11", modify
      label def ym1 12 "2001M12", modify
      label def ym1 13 "2002M01", modify
      label def ym1 14 "2002M02", modify
      label def ym1 15 "2002M03", modify
      label def ym1 16 "2002M04", modify
      label def ym1 17 "2002M05", modify
      label def ym1 18 "2002M06", modify
      label def ym1 19 "2002M07", modify
      label def ym1 20 "2002M08", modify
      label def ym1 21 "2002M09", modify
      label def ym1 22 "2002M10", modify
      label def ym1 23 "2002M11", modify
      label def ym1 24 "2002M12", modify
      label def ym1 25 "2003M01", modify
      label def ym1 26 "2003M02", modify
      label def ym1 27 "2003M03", modify
      label def ym1 28 "2003M04", modify
      label def ym1 29 "2003M05", modify
      label def ym1 30 "2003M06", modify
      label def ym1 31 "2003M07", modify
      label def ym1 32 "2003M08", modify
      label def ym1 33 "2003M09", modify
      label def ym1 34 "2003M10", modify
      label def ym1 35 "2003M11", modify
      label def ym1 36 "2003M12", modify
      label def ym1 37 "2004M01", modify
      label def ym1 38 "2004M02", modify
      label def ym1 39 "2004M03", modify
      label def ym1 40 "2004M04", modify
      label values importer1 importer1
      label def importer1 1 "CHN", modify
      The above is part of my data.

      But the time variable can't be displayed properly here, it show "1 2 3 4 5......" instead of "2001M01 2002M02......". I'm a little confused.
      Last edited by Kendal zhang; 22 Sep 2022, 00:25.

      Comment


      • #4
        Kendal:
        the issue you're experiencing is due to a previous -encode- of your -timevar-, that made Stata reporting levels instead of dates.
        The following code will probably do the trick:
        Code:
        . decode ym1, g(string_ym1)
        
        . generate nummonth = monthly( string_ym1 , "YM")
        
        . format nummonth %tm
        
        . xtset importer1 nummonth
        
        Panel variable: importer1 (strongly balanced)
         Time variable: nummonth, 2001m1 to 2004m4
                 Delta: 1 month
        
        .
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Thank you, Carlo. But a new problem appears after that. I want to make regression, and here is the code:

          xtreg imports cconflict, fe

          and it returns "no observations". I am not able to find the causes.

          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input long importer1 str3 exporter float(nummonth imports cconflict)
          1 "USA" 492  19437.69  -279.3
          1 "USA" 493  19689.31  -491.9
          1 "USA" 494  19940.93  -808.2
          1 "USA" 495  20192.55 -4415.7
          1 "USA" 496  20444.17 -1636.7
          1 "USA" 497 20695.793  -436.2
          1 "USA" 498  20947.41 -1322.4
          1 "USA" 499 21199.033  -589.8
          1 "USA" 500 21450.654 -1021.2
          1 "USA" 501 21702.275  -675.9
          1 "USA" 502 21953.895  -213.2
          1 "USA" 503 22205.516  -224.6
          1 "USA" 504 22457.137  -393.2
          1 "USA" 505  22957.17  -440.2
          1 "USA" 506   23457.2  -569.3
          1 "USA" 507 23957.227  -221.4
          1 "USA" 508  24457.26  -196.4
          1 "USA" 509  24957.29    -183
          1 "USA" 510  25457.32    -309
          1 "USA" 511  25957.35    -244
          1 "USA" 512  26457.38  -395.7
          1 "USA" 513  26957.41    -303
          1 "USA" 514  27457.44  -227.2
          1 "USA" 515  27957.47  -328.1
          1 "USA" 516   28457.5  -535.9
          1 "USA" 517 29011.766    -582
          1 "USA" 518  29566.03  -730.4
          1 "USA" 519   30120.3  -417.2
          1 "USA" 520 30674.564  -290.8
          1 "USA" 521  31228.83  -199.5
          1 "USA" 522 31783.096    -388
          1 "USA" 523  32337.36  -424.9
          1 "USA" 524  32891.63  -331.6
          1 "USA" 525  33445.89  -481.9
          1 "USA" 526 34000.156  -412.4
          1 "USA" 527 34554.426  -616.9
          1 "USA" 528  35108.69    -525
          1 "USA" 529 35533.434  -609.4
          1 "USA" 530  35958.18  -655.2
          1 "USA" 531 36382.926  -576.6
          1 "USA" 532 36807.668  -452.7
          1 "USA" 533 37232.414  -490.3
          1 "USA" 534 37657.156    -419
          1 "USA" 535 38081.902  -304.5
          1 "USA" 536  38506.65  -366.2
          1 "USA" 537  38931.39    -149
          1 "USA" 538  39356.14  -170.2
          1 "USA" 539  39780.88  -231.2
          1 "USA" 540  40205.63  -153.8
          1 "USA" 541  41296.01  -282.8
          1 "USA" 542  42386.39  -328.2
          1 "USA" 543  43476.78  -140.4
          1 "USA" 544  44567.16  -459.2
          1 "USA" 545  45657.55  -262.2
          1 "USA" 546  46747.94  -348.7
          1 "USA" 547  47838.32  -303.6
          1 "USA" 548  48928.71  -408.2
          1 "USA" 549  50019.09  -163.2
          1 "USA" 550  51109.48  -316.6
          1 "USA" 551  52199.86  -295.9
          1 "USA" 552  53290.25  -264.3
          1 "USA" 553  54080.27  -209.8
          1 "USA" 554   54870.3    -687
          1 "USA" 555  55660.32  -629.3
          1 "USA" 556  56450.34  -589.9
          1 "USA" 557  57240.36    -704
          1 "USA" 558  58030.39  -286.6
          1 "USA" 559  58820.41  -592.5
          1 "USA" 560  59610.43    -848
          1 "USA" 561  60400.46  -429.8
          1 "USA" 562  61190.48  -734.3
          1 "USA" 563   61980.5    -623
          1 "USA" 564  62770.52 -1100.3
          1 "USA" 565  63248.43  -728.1
          1 "USA" 566  63726.33 -1086.3
          1 "USA" 567  64204.24   -1491
          1 "USA" 568  64682.14 -1316.7
          1 "USA" 569  65160.05 -1425.1
          1 "USA" 570 65637.945 -1136.2
          1 "USA" 571  66115.85 -1016.9
          1 "USA" 572  66593.76 -1584.3
          1 "USA" 573 67071.664 -2445.4
          1 "USA" 574  67549.56 -1712.1
          1 "USA" 575  68027.47 -1246.8
          1 "USA" 576 68505.375 -1097.2
          1 "USA" 577 68430.086 -2484.8
          1 "USA" 578   68354.8 -1801.6
          1 "USA" 579 68279.516 -2477.5
          1 "USA" 580  68204.23 -1171.7
          1 "USA" 581  68128.94 -1527.3
          1 "USA" 582  68053.65 -1342.4
          1 "USA" 583  67978.37 -1716.7
          1 "USA" 584  67903.08  -757.7
          1 "USA" 585  67827.79 -1285.7
          1 "USA" 586  67752.51  -897.4
          1 "USA" 587  67677.22   -1058
          1 "USA" 588  67601.93 -1819.3
          1 "USA" 589  69292.16 -1532.8
          1 "USA" 590  70982.39 -3767.1
          1 "USA" 591  72672.62 -3104.2
          end
          format %tm nummonth
          label values importer1 importer1
          label def importer1 1 "CHN", modify

          Comment


          • #6
            Kendal:
            your -panelvar- is composed of one country only (hence, it is not a panel):
            Code:
            . xtreg imports cconflict, fe
            no observations
            r(2000);
            
            . reg imports i.importer1 cconflict
            note: 1.importer1 omitted because of collinearity.
            
                  Source |       SS           df       MS      Number of obs   =       100
            -------------+----------------------------------   F(1, 98)        =     25.89
                   Model |  6.4481e+09         1  6.4481e+09   Prob > F        =    0.0000
                Residual |  2.4412e+10        98   249097864   R-squared       =    0.2089
            -------------+----------------------------------   Adj R-squared   =    0.2009
                   Total |  3.0860e+10        99   311714350   Root MSE        =     15783
            
            ------------------------------------------------------------------------------
                 imports | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
            -------------+----------------------------------------------------------------
               importer1 |
                    CHN  |          0  (omitted)
               cconflict |  -10.64316   2.091889    -5.09   0.000    -14.79444   -6.491871
                   _cons |   36517.03   2307.641    15.82   0.000     31937.59    41096.47
            ------------------------------------------------------------------------------
            
            . 
            
            
            .
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Carlo,

              I have "importer" and "exporter", so there are two countries in my dataset. But I can't include the "exporter" when doing the xtreg.

              Kind regards,
              Kendal

              Comment


              • #8
                This is part of my original data
                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input float nummonth str3(importer exporter) float(imports cconflict)
                492 "CHN" "USA"  19437.69  -279.3
                493 "CHN" "USA"  19689.31  -491.9
                494 "CHN" "USA"  19940.93  -808.2
                495 "CHN" "USA"  20192.55 -4415.7
                496 "CHN" "USA"  20444.17 -1636.7
                497 "CHN" "USA" 20695.793  -436.2
                498 "CHN" "USA"  20947.41 -1322.4
                499 "CHN" "USA" 21199.033  -589.8
                500 "CHN" "USA" 21450.654 -1021.2
                501 "CHN" "USA" 21702.275  -675.9
                502 "CHN" "USA" 21953.895  -213.2
                503 "CHN" "USA" 22205.516  -224.6
                504 "CHN" "USA" 22457.137  -393.2
                505 "CHN" "USA"  22957.17  -440.2
                506 "CHN" "USA"   23457.2  -569.3
                507 "CHN" "USA" 23957.227  -221.4
                508 "CHN" "USA"  24457.26  -196.4
                509 "CHN" "USA"  24957.29    -183
                510 "CHN" "USA"  25457.32    -309
                511 "CHN" "USA"  25957.35    -244
                512 "CHN" "USA"  26457.38  -395.7
                513 "CHN" "USA"  26957.41    -303
                514 "CHN" "USA"  27457.44  -227.2
                515 "CHN" "USA"  27957.47  -328.1
                516 "CHN" "USA"   28457.5  -535.9
                517 "CHN" "USA" 29011.766    -582
                518 "CHN" "USA"  29566.03  -730.4
                519 "CHN" "USA"   30120.3  -417.2
                520 "CHN" "USA" 30674.564  -290.8
                521 "CHN" "USA"  31228.83  -199.5
                522 "CHN" "USA" 31783.096    -388
                523 "CHN" "USA"  32337.36  -424.9
                524 "CHN" "USA"  32891.63  -331.6
                525 "CHN" "USA"  33445.89  -481.9
                526 "CHN" "USA" 34000.156  -412.4
                end
                format %tm nummonth
                There are two countries,and the date is from 2001M01 to 2020M12. I think it is a panel data.

                Comment


                • #9
                  Originally posted by Carlo Lazzaro View Post
                  Kendal:
                  your -panelvar- is composed of one country only (hence, it is not a panel):
                  Code:
                  . xtreg imports cconflict, fe
                  no observations
                  r(2000);
                  
                  . reg imports i.importer1 cconflict
                  note: 1.importer1 omitted because of collinearity.
                  
                  Source | SS df MS Number of obs = 100
                  -------------+---------------------------------- F(1, 98) = 25.89
                  Model | 6.4481e+09 1 6.4481e+09 Prob > F = 0.0000
                  Residual | 2.4412e+10 98 249097864 R-squared = 0.2089
                  -------------+---------------------------------- Adj R-squared = 0.2009
                  Total | 3.0860e+10 99 311714350 Root MSE = 15783
                  
                  ------------------------------------------------------------------------------
                  imports | Coefficient Std. err. t P>|t| [95% conf. interval]
                  -------------+----------------------------------------------------------------
                  importer1 |
                  CHN | 0 (omitted)
                  cconflict | -10.64316 2.091889 -5.09 0.000 -14.79444 -6.491871
                  _cons | 36517.03 2307.641 15.82 0.000 31937.59 41096.47
                  ------------------------------------------------------------------------------
                  
                  .
                  
                  
                  .
                  Thank you,Carlo. I have solved the problem by making changes about "importer" and "exporter".

                  Comment

                  Working...
                  X