Announcement

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

  • Panel data with lagged independent variables and dependent variable only two periods

    Hi Member, Please, does anyone could help me?
    I need to lag and lead one independent variable in my panel with T=2.
    My dependent variable only has values for these two periods, however I need to lag and lead the independent variable for more periods and see how it will affect the Yt. I do not know how to construct this panel. Could someone suggest me something? Many thanks !

  • #2
    After you
    Code:
    xtset id time
    time series operators such as l.var (lagged value) and f.var (lead value) become available.

    But if you have only two periods on the independent variable, you cannot lead and lag it.

    Comment


    • #3
      Joro Kolev Hi Prof. thank you for answering. I do have many periods for the indep. var, but I just have two periods for the dep. var. and I wish to lag and lead more than two periods. I had tried to lag/lead using the xtset id time but it is not possible because I just have two periods for the dep. var.

      Many thanks.

      Comment


      • #4
        ... So how can I lag/lead the indep. var more periods than what I have for the dep. var. And I do not want to lag/lead the dep. var.
        Many thanks.

        Comment


        • #5
          I do not understand. Show what you typed, and what Stata returned back to you. Even better if you can provide a sample of your data with -dataex-.



          Originally posted by juliana pinto View Post
          Joro Kolev Hi Prof. thank you for answering. I do have many periods for the indep. var, but I just have two periods for the dep. var. and I wish to lag and lead more than two periods. I had tried to lag/lead using the xtset id time but it is not possible because I just have two periods for the dep. var.

          Many thanks.

          Comment


          • #6
            Joro Kolev Prof, thank you so much for answering.
            I never used the dataex, I will try. Many thanks.
            This is what I have. Dep. variable is points. I just have points for two days. My t=2 because I am using FE per individual and not per county.
            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input double id byte day float(year points tempe) long county
            150000000005 1 2015     548.3 16.278925 3550308
            150000000005 2 2015     651.1 18.446114 3550308
            150000000007 1 2015     531.8 16.823925 3304557
            150000000007 2 2015     484.9 14.059508 3304557
            150000000021 1 2015    530.65 16.823925 3304557
            150000000021 2 2015    528.75 14.059508 3304557
            150000000026 1 2015    512.55 16.094667 3303500
            150000000026 2 2015     445.2 13.166375 3303500
            150000000028 1 2015    561.65 16.278925 3550308
            150000000028 2 2015     566.2 18.446114 3550308
            150000000029 1 2015     596.1 16.278925 3550308
            150000000029 2 2015    575.95 18.446114 3550308
            150000000033 1 2015    554.25 16.823925 3304557
            150000000033 2 2015     517.5 14.059508 3304557
            150000000051 1 2015     599.1 16.278925 3550308
            150000000051 2 2015     519.3 18.446114 3550308
            150000000057 1 2015    647.95 16.823925 3304557
            150000000057 2 2015       650 14.059508 3304557
            150000000071 1 2015     661.3  21.25245 3509502
            150000000071 2 2015     611.8 15.074903 3509502
            150000000094 1 2015    596.85 16.278925 3550308
            150000000094 2 2015    486.35 18.446114 3550308
            150000000103 1 2015     587.1 16.823925 3304557
            150000000103 2 2015     620.6 14.059508 3304557
            150000000108 1 2015    627.15 16.823925 3304557
            150000000108 2 2015    662.85 14.059508 3304557
            150000000121 1 2015    491.55 16.599346 3513801
            150000000121 2 2015    505.95 18.745453 3513801
            150000000122 1 2015     703.7 16.823925 3304557
            150000000122 2 2015     667.8 14.059508 3304557
            150000000132 1 2015    663.65  21.25245 3509502
            150000000132 2 2015    643.15 15.074903 3509502
            150000000140 1 2015     504.7 16.278925 3550308
            150000000140 2 2015    474.05 18.446114 3550308
            150000000164 1 2015    538.35 16.823925 3304557
            150000000164 2 2015    500.95 14.059508 3304557
            150000000169 1 2015     537.9 16.823925 3304557
            150000000169 2 2015    511.85 14.059508 3304557
            150000000186 1 2015 545.44995 16.278925 3550308
            150000000186 2 2015     530.3 18.446114 3550308
            150000000187 1 2015    522.75 16.823925 3304557
            150000000187 2 2015    526.55 14.059508 3304557
            150000000212 1 2015     508.2 16.278925 3550308
            150000000212 2 2015       465 18.446114 3550308
            150000000213 1 2015    621.85 16.278925 3550308
            150000000213 2 2015     588.9 18.446114 3550308
            150000000217 1 2015     515.3 16.278925 3550308
            150000000217 2 2015     476.7 18.446114 3550308
            150000000222 1 2015    537.85 16.823925 3304557
            150000000222 2 2015    607.45 14.059508 3304557
            150000000225 1 2015     471.2 16.823925 3304557
            150000000225 2 2015       525 14.059508 3304557
            150000000228 1 2015     550.9  15.84224 3552809
            150000000228 2 2015     501.2 14.033832 3552809
            150000000233 1 2015       557 16.823925 3304557
            150000000233 2 2015     461.8 14.059508 3304557
            150000000243 1 2015    492.85 16.278925 3550308
            150000000243 2 2015    465.85 18.446114 3550308
            150000000266 1 2015     499.6 16.823925 3304557
            150000000266 2 2015     463.8 14.059508 3304557
            150000000273 1 2015     533.9 16.511492 3518800
            150000000273 2 2015     468.2  9.885218 3518800
            150000000280 1 2015    573.35 16.094667 3303500
            150000000280 2 2015    567.25 13.166375 3303500
            150000000288 1 2015    551.65  34.41621 3304201
            150000000288 2 2015    497.45  31.70779 3304201
            150000000289 1 2015       598  23.00072 3534401
            150000000289 2 2015    629.25  21.45692 3534401
            150000000290 1 2015       653 16.823925 3304557
            150000000290 2 2015     754.9 14.059508 3304557
            150000000305 1 2015     603.6  34.41621 3304201
            150000000305 2 2015     644.4  31.70779 3304201
            150000000306 1 2015     670.5 16.278925 3550308
            150000000306 2 2015     672.7 18.446114 3550308
            150000000320 1 2015    549.65 18.958334 3303203
            150000000320 2 2015     474.1 14.416667 3303203
            150000000341 1 2015    501.75 15.958333 3506003
            150000000341 2 2015    443.15 15.791666 3506003
            150000000346 1 2015     659.2 16.278925 3550308
            150000000346 2 2015    704.15 18.446114 3550308
            150000000359 1 2015     519.2 16.599346 3513801
            150000000359 2 2015     456.4 18.745453 3513801
            150000000360 1 2015     565.6 16.278925 3550308
            150000000360 2 2015    503.15 18.446114 3550308
            150000000362 1 2015    539.35 16.823925 3304557
            150000000362 2 2015     474.1 14.059508 3304557
            150000000374 1 2015     544.7 33.333332 3300456
            150000000374 2 2015    519.95 22.708334 3300456
            150000000382 1 2015    420.85 16.823925 3304557
            150000000382 2 2015     432.2 14.059508 3304557
            150000000384 1 2015    496.35 16.823925 3304557
            150000000384 2 2015     464.5 14.059508 3304557
            150000000393 1 2015    542.85  36.20833 3549805
            150000000393 2 2015     521.5    34.625 3549805
            150000000404 1 2015    464.55  9.291667 3554102
            150000000404 2 2015     527.6      5.75 3554102
            150000000407 1 2015 527.44995 16.278925 3550308
            150000000407 2 2015     486.5 18.446114 3550308
            150000000410 1 2015       573 16.278925 3550308
            150000000410 2 2015     544.2 18.446114 3550308
            end
            Then,
            I have to lead and lag the indep. variable tempe let's say 3 days before and 3 days after the actual days in the Sample. I do have data to create the lags. What I do not have is data for the points. I just want the var tempe lead/ lagged. But I do not know how to build this panel since I just have data for the actual 2 periods as above. That's where I am stuck. I do not know how to build such lag and lead structure for the indep. var. if I need to lag/lead for more periods than I have for the actual dep. var data.

            Comment


            • #7
              In this data that you are showing you do not have tempe for more than the two days. Hence this is the maximum lag and lead that you can do:

              Code:
              . xtset id day
                     panel variable:  id (strongly balanced)
                      time variable:  day, 1 to 2
                              delta:  1 unit
              
              . gen lagtempe = l.tempe
              (50 missing values generated)
              
              . gen fwtempe = f.tempe
              (50 missing values generated)
              
              . list id day tempe lagtempe fwtempe in 1/10, sep(2)
              
                   +--------------------------------------------------+
                   |        id   day      tempe   lagtempe    fwtempe |
                   |--------------------------------------------------|
                1. | 1.500e+11     1   16.27892          .   18.44611 |
                2. | 1.500e+11     2   18.44611   16.27892          . |
                   |--------------------------------------------------|
                3. | 1.500e+11     1   16.82393          .   14.05951 |
                4. | 1.500e+11     2   14.05951   16.82393          . |
                   |--------------------------------------------------|
                5. | 1.500e+11     1   16.82393          .   14.05951 |
                6. | 1.500e+11     2   14.05951   16.82393          . |
                   |--------------------------------------------------|
                7. | 1.500e+11     1   16.09467          .   13.16638 |
                8. | 1.500e+11     2   13.16638   16.09467          . |
                   |--------------------------------------------------|
                9. | 1.500e+11     1   16.27892          .   18.44611 |
               10. | 1.500e+11     2   18.44611   16.27892          . |
                   +--------------------------------------------------+
              If you have tempe for more than the two days you need to use this other data (that you are not showing). In this other data all the available data for tempe should be present, and when points is not available it should be simply missing.

              Comment


              • #8
                Joro Kolev Prof. Thank you for your reply!
                In this other data per county, I have 4 months with 30 days each of tempe data. What I do not know is how to merge these two data sets if I do not have the var. points for so many time periods.
                Thank you very much .

                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input float(day month tempe) long county float date2
                15 10 25.424654 3300407 21107
                27 11 35.068428 3300407 20785
                 6 10  20.84275 3300407 20367
                24 12 14.315747 3300407 20812
                18 10 13.967454 3300407 20379
                23 11 29.101946 3300407 20415
                22  9  74.66239 3300407 20353
                18  9  77.22729 3300407 21080
                27  9  55.57271 3300407 21089
                25  9   50.2565 3300407 20356
                 4  9 28.390306 3300407 20335
                17 10  61.51863 3300407 20378
                27  9 36.979443 3300407 20358
                28 12 20.956894 3300407 20816
                 6  9 16.689037 3300407 20337
                19 12 13.144682 3300407 20807
                29 12  23.83589 3300407 20451
                23  9  26.28311 3300407 20720
                 2  9  47.61088 3300407 20699
                16 12 34.087112 3300407 20438
                 5 10  13.36771 3300407 20366
                 8 11 29.733557 3300407 20400
                20 10  45.14186 3300407 20381
                18 11  33.04691 3300407 21141
                 9 10  48.45824 3300407 21101
                12 10 28.420383 3300407 20739
                 8 10  41.30922 3300407 20369
                28 12  30.67051 3300407 21181
                12 12 32.591614 3300407 21165
                 1  9  43.28534 3300407 21063
                31 12 28.298475 3300407 20819
                 3 10  30.85331 3300407 21095
                21  9  10.22894 3300407 20718
                 9 10  73.78294 3300407 20370
                17 11  34.91567 3300407 20409
                21 12  45.75399 3300407 21174
                29 10   26.0623 3300407 20390
                21 11  32.30288 3300407 20413
                22 12  38.58688 3300407 20444
                19  9  54.62376 3300407 20350
                 1 12  27.72946 3300407 21154
                26 11 24.865446 3300407 20418
                 3 12  26.32519 3300407 20791
                 6 12  41.28276 3300407 21159
                17 11 14.445255 3300407 20775
                14 12 12.985993 3300407 20802
                29 11 32.436863 3300407 21152
                 2 11  42.01774 3300407 21125
                15 12  42.88795 3300407 21168
                 2 12  29.65631 3300407 21155
                23 10  41.68292 3300407 20384
                25 10 22.127354 3300407 20386
                20 11 18.707834 3300407 20778
                14 11  35.16117 3300407 20406
                 3 11  38.24588 3300407 21126
                27 10  40.98009 3300407 20388
                28 10  36.98596 3300407 20389
                27 12  29.78937 3300407 20449
                27 11  40.97515 3300407 21150
                 4 12  38.43327 3300407 20426
                30 10  27.52023 3300407 20391
                22 11 26.168156 3300407 20780
                29 11 34.791145 3300407 20421
                19 11   12.3396 3300407 20777
                 3  9  39.65053 3300407 20700
                12 12 21.198324 3300407 20800
                23 10  25.37599 3300407 21115
                20  9  44.38488 3300407 20351
                22  9 18.081823 3300407 20719
                17 12 21.024683 3300407 20805
                23 12  35.64581 3300407 20445
                21 10 21.288784 3300407 20748
                 7 11 27.780764 3300407 20399
                 6 12  31.65142 3300407 20428
                 9 11  53.84618 3300407 20401
                13  9  10.90521 3300407 20344
                22 12 16.926943 3300407 20810
                 5 10 10.751817 3300407 20732
                31 10 26.398174 3300407 20758
                 2 12   32.7607 3300407 20790
                21 10  60.08746 3300407 20382
                29 11 14.975795 3300407 20787
                26 12 31.363426 3300407 21179
                 4 11 65.231804 3300407 20396
                27  9  13.03224 3300407 20724
                 4  9 38.116665 3300407 21066
                 7  9  49.42125 3300407 20704
                25 10 37.494507 3300407 20752
                20 11  32.39119 3300407 20412
                 6 11  25.97806 3300407 21129
                18 12 38.119293 3300407 20440
                 4 10  21.28467 3300407 20365
                 3 12  26.94255 3300407 20425
                 5  9  47.48283 3300407 21067
                 7 11  38.84344 3300407 21130
                30 11 36.621983 3300407 21153
                 2 12  48.54274 3300407 20424
                 4 12 17.961258 3300407 20792
                25 12  28.88255 3300407 20447
                28 10  19.89036 3300407 20755
                end

                Comment


                • #9
                  Do I understand that you have two days of data on y and 120 days on your key x (temp)? You can create a merged data set that matches up the same two days on y and x. Then, you have data on x both before and after, but y is missing both before and after. Then you could put in lots of lads (and leads if you must).

                  Comment


                  • #10
                    Jeff Wooldridge Hi Prof. Thank you very much for your answer. I am trying to use the fillin to expand my original data with only two days of y and sx variables. And then after that I can merge with the other data with 120 days of x data for each y that I still only have 2 days of data. But I don't know if it will work.

                    Comment


                    • #11
                      Good luck! I’ve struggled with such things. Can you do a matched merge on id and date? I think there’s a way to do that so each id would then have 120 records. But others on here know much more than I.

                      Comment


                      • #12
                        Jeff Wooldridge Thank you very much! Yes, I found my way here on statalist! Many thanks!! :-)

                        Comment

                        Working...
                        X