Announcement

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

  • Year group categories from dates

    I am trying to generate two decade groups "2010 or earlier" and "2011 and above" for dates of CLL diagnosis and I am not getting the right answers in date and floor functions.

    This code clearly does not seem right

    gen timeperiod = 0 if clldate < 1/1/2011

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float clldate
    17209
    19045
    20590
    20529
        .
    17016
    20996
    17532
    17167
    17532
    19788
    15857
    20083
    15675
    17468
    17532
    18628
    16071
    19792
    17532
    11688
    19449
    17532
    10227
    16802
    17532
    17167
     9132
    19484
    19359
    15706
    16802
    19502
    17532
    18749
    17167
    18263
        .
    10958
    15706
    14610
    16802
        .
    17843
    10593
    15522
    16802
    16802
        .
    14245
        .
        .
    16071
    16887
    14976
    16539
    13515
    16713
    15264
        .
    14335
    15341
    10227
        .
    13515
    14976
    15219
    13149
    15111
    14610
    13515
    12419
        .
    14610
    13635
        .
    16204
    20369
    17714
    18049
    18597
    17563
    21608
    17785
    19175
    21933
    20675
    14031
    19632
    19024
    19237
    21117
    22103
    21011
    19715
    20118
    20292
    16496
    16802
    21094
    end
    format %td clldate

  • #2
    Perhaps this code applied to your example data will start you in a useful direction.
    Code:
    . generate timeperiod = clldate > td(31/12/2010) if clldate!=.
    (10 missing values generated)
    
    . tabstat clldate, statistics(min max) by(timeperiod) missing format(%td)
    
    Summary for variables: clldate
    Group variable: timeperiod 
    
    timeperiod |       Min       Max
    -----------+--------------------
             0 | 01jan1985 01dec2010
             1 | 01jan2011 07jul2020
             . |         .         .
    -----------+--------------------
         Total | 01jan1985 07jul2020
    --------------------------------
    Stata's "date and time" variables are complicated and there is a lot to learn. If you have not already read the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, do so now. If you have, it's time for a refresher. After that, the help datetime documentation will usually be enough to point the way. You can't remember everything; even the most experienced users end up referring to the help datetime documentation or back to the manual for details. But at least you will get a good understanding of the basics and the underlying principles. An investment of time that will be amply repaid.

    All Stata manuals are included as PDFs in the Stata installation and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

    Comment


    • #3
      Thanks much, William. Will go through help datetime. I just learnt about the MD20Y mask yesterday. Another nice thing for today from you.

      Comment

      Working...
      X