stata

Dropping observations by date


I have a date variable in Stata MP 17.0 doi which is in %td format.

I want to drop specific dates but the commands I am using either do not drop observations or show type mismatch.

I changed the format to %tdNN/DD/CCYY but still the outcome is same.

Steps I did- enter image description here


Solution

  • A daily date variable is numeric, so comparison with a string yields a type mismatch.

    The numeric expression you typed just yields a small fraction because the /s are interpreted as division.

    . di 03/19/2024
    .00007801
    

    There are various ways to do what you want. One is

    drop if date == mdy(3, 19, 2024)
    

    Changing the display format doesn't change what is stored.

    There is no good understanding of dates without reading the help on dates.

    help dates