Announcement

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

  • Difference in dates to deduce months

    Hello everyone!

    I would really appreciate help on the below.

    I would like to find the difference between one variable named "Birthyear_C" (with e.g. 1985m5) and 2019m1 which is Jan 2019 and in doing so generate the number of months and round it up for my analysis of an event study model. I have provided my simple command and data below. The error reads "2019m1 invalid name". I have gone through help datetime but still can't figure out how to transform the 2019m1 to a Stata "month count" format. 21550 for example represents the count of days from 1.1.1960 to 1.1.2019 but I only want to calculate the months since my "Birthyear_C" only has month and year.


    Code:
    g montht = round(birthyear_C-2019m1)
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte b1_ int b2_ float birthyear_C
     5 -29 328
     7 -29 330
     9 -29 332
    10 -29 333
    11 -29 334
    11 -29 334
    12 -29 335
    12 -29 335
     1 -28 336
     2 -28 337
     2 -28 337
     2 -28 337
     2 -28 337
     2 -28 337
     2 -28 337
     2 -28 337
     3 -28 338
     3 -28 338
     3 -28 338
     4 -28 339
     5 -28 340
     5 -28 340
     6 -28 341
     7 -28 342
     7 -28 342
     7 -28 342
     7 -28 342
     7 -28 342
     7 -28 342
     8 -28 343
     8 -28 343
     8 -28 343
     8 -28 343
     8 -28 343
     8 -28 343
     8 -28 343
     9 -28 344
    10 -28 345
    10 -28 345
    10 -28 345
    11 -28 346
    11 -28 346
    12 -28 347
    12 -28 347
     1 -27 348
     1 -27 348
     2 -27 349
     2 -27 349
     2 -27 349
     2 -27 349
     2 -27 349
     3 -27 350
     3 -27 350
     3 -27 350
     4 -27 351
     4 -27 351
     4 -27 351
     4 -27 351
     5 -27 352
     5 -27 352
     5 -27 352
     5 -27 352
     6 -27 353
     6 -27 353
     6 -27 353
     6 -27 353
     6 -27 353
     7 -27 354
     7 -27 354
     7 -27 354
     7 -27 354
     7 -27 354
     8 -27 355
     8 -27 355
     8 -27 355
     8 -27 355
     8 -27 355
     8 -27 355
     8 -27 355
     9 -27 356
     9 -27 356
     9 -27 356
    10 -27 357
    10 -27 357
    10 -27 357
    10 -27 357
    10 -27 357
    11 -27 358
    11 -27 358
    11 -27 358
    11 -27 358
    11 -27 358
    11 -27 358
    11 -27 358
    12 -27 359
    12 -27 359
    12 -27 359
    12 -27 359
    12 -27 359
    12 -27 359
    end
    format %tm birthyear_C

  • #2
    Code:
    g montht = birthyear_C-tm(2019m1)
    I don't see the logic of rounding here. The result is in integer months.

    Code:
    help  tm()

    Comment


    • #3
      Code:
      gen montht = birthyear_C - tm(2019m1)
      I don't understand the point of -round()- here. Both birtheyar_C and tm(2019m1) are integers--there is nothing to round.

      Added: Crossed with #2.

      Comment


      • #4
        Thanks a lot Andrew Musau and Clyde Schechter. Yes, the months are whole numbers and don't need rounding.

        Comment

        Working...
        X