Announcement

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

  • How to expand a dataset by 1 week backward

    Hi,

    I would like to expand the dataset by one period backward with a weekly time series dataset. Here is what I have:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(w_date closeanonymity)
    3212  -.07453440740494499
    3213     -.11201581072541
    3214   .04650582362758038
    3215   .09057059803945666
    3216 .0009825186085834492
    3217  -.16465546472929637
    3218  -.10327840076331218
    3219  -.15560464683759367
    3220   -.2868120202786998
    3221   -.3258841641309259
    3222   -.3327205765329304
    3223  -.31961745290325916
    3224  -.26222046986742675
    3225  -.20663110145042796
    3226   -.3206685932589224
    3227  -.35852332182981206
    3228   -.4651596783969958
    3229   -.4637146143870273
    3230   -.4619871204112953
    3231   -.4574751448500801
    3232   -.3093820467796068
    3233  -.26106590245418315
    3234   -.3398592328611313
    3235   -.3664738704478687
    3236   -.4188043793908631
    3237   -.4033281009480306
    3238   -.4124801422354588
    3239  -.43229760801132255
    3240  -.37120071672328536
    3241    -.450118623231906
    3242   -.5865024613785637
    3243   -.5890292276520772
    3244   -.6186922442393452
    3245   -.5770453072124755
    3246   -.5635392246014329
    3247    -.496780592116965
    3248   -.5032697211266051
    3249   -.5282170209371102
    3250   -.5643123612949275
    3251    -.609999052559115
    3252   -.6010931502084521
    3253   -.5752631673809323
    3254   -.5590466609705688
    3255   -.5776376572340056
    3256   -.5438718491198751
    3257   -.5668957088891466
    3258   -.5831774631993886
    3259   -.6187178329476606
    3260    -.646653088129276
    3261   -.6804035616109922
    3262   -.6803588878861471
    end
    format %tw w_date
    That is, I would like to create a first row with w_date == 2021w40 and all other empty columns. Can someone help? Thanks.

  • #2
    Code:
    insobs 1
    replace w_date = 3211 in l

    Comment


    • #3
      Thanks Øyvind! However I need to add the observation at the beginning of the sample and not at the end.

      Plus, the initial date will change as I am trying different samples. Is there any way to generate the first date automatically without inputting "3211"? Thanks!
      Last edited by Francois Durant; 07 Dec 2022, 01:35.

      Comment


      • #4
        Code:
        insobs 1, before(1)
        replace w_date = w_date[_n+1] - 1 in 1

        Comment

        Working...
        X