Announcement

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

  • Add 1 year to every date and add a reference date as well

    Hello,

    I am working on a dataset where I try to set a reference date for every date thats in my data. So for example for the 31dec2019 the reference date should be 01jun2020. The same for 31Jul2018 the reference date would be 01jun2019. So basically I want every date to be 01junYEAR+1

    I tried this code but it only adds 1 year to the date

    Code:
    gen reference_date = datadate + 365
    format %tdD_m_Y reference_date
    My thoughts were to create a new year variable and at 01jun+Year

    Code:
    gen year1 = year(dofm(reference_date))
    but I am not sure if I can add just "01jun" wihtout breaking the data.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str6 gvkey long datadate str10 cusip float(book_equity year)
    "001004" 20970 "000361105"    951.4 2017
    "001004" 21335 "000361105"      952 2018
    "001004" 21700 "000361105"    905.9 2019
    "001004" 22066 "000361105"    902.6 2020
    "001045" 21184 "02376R102"     3959 2017
    "001050" 21184 "125141101"  196.779 2017
    "001050" 21549 "125141101"  187.315 2018
    "001050" 21914 "125141101"   198.96 2019
    "001062" 21153 "G3156P103"  244.202 2017
    "001062" 21518 "G3156P103"  194.834 2018
    "001062" 21883 "G3156P103"  285.879 2019
    "001072" 20909 "002444107" 2217.436 2017
    "001072" 21274 "002444107" 2256.338 2018
    "001072" 21639 "002444107" 2398.415 2019
    "001075" 21184 "723484101"  6903.07 2017
    "001075" 21549 "723484101" 7230.741 2018
    "001075" 21914 "723484101" 7619.455 2019
    "001076" 21184 "00258R109" 1950.596 2017
    "001076" 21549 "00258R109" 2028.208 2018
    "001076" 21914 "00258R109" 2047.654 2019
    "001078" 21184 "002824100"    32903 2017
    "001078" 21549 "002824100"    32580 2018
    "001078" 21914 "002824100"    32634 2019
    "001094" 21000 "004446100"  412.392 2017
    "001094" 21365 "004446100"   96.821 2018
    "001096" 21184 "617577101" 3729.557 2017
    "001096" 21549 "617577101" 4149.309 2018
    "001096" 21914 "617577101" 4282.692 2019
    "001097" 21184 "004616207"   29.967 2017
    "001097" 21549 "004616207"   28.305 2018
    "001097" 21914 "004616207"   31.629 2019
    "001104" 21184 "004816104"   49.938 2017
    "001104" 21549 "004816104"   52.332 2018
    "001104" 21914 "004816104"   55.754 2019
    "001117" 21184 "05587G104"   32.007 2017
    "001117" 21549 "05587G104"   27.712 2018
    "001117" 21914 "05587G104"   23.276 2019
    "001121" 21184 "006351308"  150.421 2017
    "001121" 21549 "006351308"  150.836 2018
    "001121" 21914 "006351308"  157.963 2019
    "001161" 21184 "007903107"      622 2017
    "001161" 21549 "007903107"     1277 2018
    "001161" 21914 "007903107"     2838 2019
    "001166" 21184 "N07045102" 2434.906 2017
    "001166" 21549 "N07045102" 1893.341 2018
    "001166" 21914 "N07045102" 2063.455 2019
    "001177" 21184 "00817Y108"    15580 2017
    "001186" 21184 "008474108" 5774.332 2017
    "001186" 21549 "008474108"  5346.72 2018
    "001186" 21914 "008474108" 6059.656 2019
    "001209" 21092 "009158106"  10864.6 2017
    "001209" 21457 "009158106"  11632.6 2018
    "001209" 21822 "009158106"  11847.4 2019
    "001209" 22188 "009158106"  13042.4 2020
    "001210" 20909 "009207101"   22.974 2017
    "001210" 21274 "009207101"    25.21 2018
    "001210" 21639 "009207101"   24.358 2019
    "001210" 22005 "009207101"   24.585 2020
    "001224" 21092 "010284008"    867.4 2017
    "001224" 21457 "010284008"    808.7 2018
    "001224" 21822 "010284008"      830 2019
    "001225" 21184 "010392009"     9701 2017
    "001225" 21549 "010392009"    10545 2018
    "001225" 21914 "010392009"    12315 2019
    "001230" 21184 "011659109"     4175 2017
    "001230" 21549 "011659109"     4263 2018
    "001230" 21914 "011659109"     5046 2019
    "001234" 21184 "049904105"    191.7 2017
    "001234" 21549 "049904105"  217.454 2018
    "001234" 21914 "049904105"  246.366 2019
    "001254" 21184 "57686G105"    963.4 2017
    "001254" 21549 "57686G105"     1068 2018
    "001254" 21914 "57686G105"   1143.3 2019
    "001257" 21184 "014752109"  343.955 2017
    "001257" 21549 "014752109"  285.092 2018
    "001257" 21914 "014752109"  253.515 2019
    "001262" 21184 "015644107"  699.098 2017
    "001262" 21549 "015644107"  750.985 2018
    "001262" 21914 "015644107"  708.901 2019
    "001266" 21092 "016230104"  187.749 2017
    "001266" 21457 "016230104"   197.27 2018
    "001266" 21822 "016230104"  226.428 2019
    "001274" 21184 "017175100" 8514.063 2017
    "001274" 21549 "017175100"  7692.71 2018
    "001274" 21914 "017175100" 8776.734 2019
    "001300" 21184 "438516106"    20170 2017
    "001300" 21549 "438516106"    19893 2018
    "001300" 21914 "438516106"    20164 2019
    "001327" 21092 "83088M102"   4074.9 2017
    "001327" 21457 "83088M102"   4111.9 2018
    "001327" 21822 "83088M102"   4135.4 2019
    "001380" 21184 "42809H107"    10905 2017
    "001380" 21549 "42809H107"     9475 2018
    "001380" 21914 "42809H107"     9147 2019
    "001388" 21184 "023771009"    14594 2017
    "001388" 21549 "023771009"    11770 2018
    "001388" 21914 "023771009"    13422 2019
    "001393" 20909 "023586100" 3454.753 2017
    "001393" 21274 "023586100" 4066.816 2018
    "001393" 21639 "023586100" 4443.359 2019
    end
    format %td datadate
    Thanks
    Last edited by Marius Bauer; 19 Nov 2020, 11:39.

  • #2
    Code:
    gen wanted = mdy(6, 1, year + 1) 
    format wanted %td

    Comment


    • #3
      thanks the code workded perfectly!

      Comment

      Working...
      X