Announcement

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

  • if date variable(DMYhms) tc fucntion

    Hello. Please tell me what is my mistake and how can I fix my do.file.

    I want to replace time=2 if emarealtime=13jun2022 06:23:23

    My do file is below.

    replace time=2 if emarealtime=tc(13jun2022 06:23:23)

    But it's wrong.

    Please help me.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double emarealtime byte(day time depression anxiety stress suicide)
    1969935675359.9998  1 1 2 3 4 2
    1969992111216.9998  1 2 3 4 4 4
         1970080709398  2 2 3 2 3 2
    1970088293271.9998  2 3 3 3 4 3
    1970165917743.9998  3 2 2 3 3 2
    1970166415113.9998  3 3 2 3 3 2
    1970251285548.0002  4 2 2 4 4 4
    1970424041636.9995  6 2 3 3 4 3
         1970423463289  6 3 3 2 4 3
         1970453128270  7 1 3 3 4 4
    1970510816231.9998  7 2 3 4 4 3
    1970556851789.0002  8 1 2 2 2 1
    1970615043172.0005  8 3 2 2 2 1
         1970625632197  9 1 3 2 3 2
    1970684873837.0005  9 2 3 3 3 2
         1970689496547  9 3 2 3 3 2
         1970720603138 10 1 3 4 4 3
    1970770168689.0005 10 2 3 2 2 2
    1970775599753.9998 10 3 3 2 2 3
    1970811853063.0002 11 1 2 3 3 2
    1970851383707.9998 11 2 4 3 5 4
    1970856084199.9998 11 2 2 3 3 3
         1970866824213 11 3 2 3 3 3
    1970896290435.9995 12 1 2 3 3 3
    1970942451298.9995 12 2 3 2 3 3
    1971028876098.9998 13 2 2 4 3 3
         1971128456706 14 3 3 5 4 4
         1971158136726 15 1 3 3 3 3
    1971210574222.9998 15 2 4 3 4 3
    1971210597606.9998 15 3 4 3 4 3
    1971374509454.9998 17 2 2 3 3 2
    1971386870327.9995 17 3 3 4 3 2
         1971430274051 18 1 2 2 3 1
    1971461496269.9998 18 2 3 3 3 2
    1971469619309.0002 18 3 2 2 3 1
         1971503028836 19 1 3 2 2 2
    1971549695244.9998 19 2 3 3 3 3
         1971559069329 19 3 4 3 4 3
    1971650300268.9995 20 3 3 3 4 3
    1971684028369.0002 21 1 3 2 2 1
         1971720785268 21 2 2 1 3 1
         1971734618965 21 3 2 2 3 3
    1971761445396.0002 22 1 2 1 2 1
         1971806551297 22 2 2 3 3 2
         1971893994643 23 2 3 4 4 3
    1971903634837.0002 23 3 3 4 4 3
    1971951154307.0005 24 1 2 3 3 1
         1971982187817 24 2 4 3 3 2
    1971990159172.0002 24 3 3 4 3 2
         1972020625785 25 1 4 3 3 3
    1972065844363.9998 25 2 3 2 2 2
    1972108656725.9998 26 1 3 3 2 2
         1972152224675 26 2 3 3 2 3
    1972194540764.0002 27 1 3 3 3 2
         1972324817454 28 2 2 4 4 2
         1972332675605 28 3 2 3 2 1
    end
    format %tc emarealtime

  • #2
    Are you sure that you want to be that specific?

    Code:
     display %20.3g tc(13jun2022 06:23:23)
    Res.:

    Code:
    . display %20.3g tc(13jun2022 06:23:23)
           1970720603000
    To test for equality, you need double equal signs:

    Code:
    replace time=2 if emarealtime==tc(13jun2022 06:23:23)

    Comment

    Working...
    X