Announcement

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

  • recode numeric variable with letters in it

    Hi, in my data, the birth year variable is as follows. You can see that the elements in this variable is not numeric year, but "01 Jan 36". I want to recode "01 Jan 36" into 1936. However, I found this variable is not a string variable but a numeric variable. Thus, "01 Jan 36" is not value labels but values. How can I recode the value "01 Jan 36" into the value 1936. I would appreciate your help. Thanks!
    Click image for larger version

Name:	byear.png
Views:	1
Size:	92.4 KB
ID:	1429805

  • #2
    You can see that the elements in this variable is not numeric year, but "01 Jan 36". I want to recode "01 Jan 36" into 1936. However, I found this variable is not a string variable but a numeric variable.
    There are at least two distinct possibilities for what this variable is, and the answer to your question is very different, depending on which of those is the case. It cannot be discerned from a listing of output like this. In order to get an answer to your question you have to show an example of the data using the -dataex- command.

    If you are running Stata version 15.1, or a completely updated version 14.2, then it is part of your official installation. If not, then run -ssc install dataex- to get it. Either way, then run -help dataex- to read the simple instructions for using it. Then use it to show an example of the data for this variable by running -dataex qa02-. Copy Stata's output from that command here into the Forum following the instructions from -help dataex-. Only with that will it be possible to solve your problem.

    I cannot emphasize enough the importance of using -dataex- here. Do not post a screenshot of the Browser, nor another image of -list- or -tab- output: that will be useless.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      There are at least two distinct possibilities for what this variable is, and the answer to your question is very different, depending on which of those is the case. It cannot be discerned from a listing of output like this. In order to get an answer to your question you have to show an example of the data using the -dataex- command.

      If you are running Stata version 15.1, or a completely updated version 14.2, then it is part of your official installation. If not, then run -ssc install dataex- to get it. Either way, then run -help dataex- to read the simple instructions for using it. Then use it to show an example of the data for this variable by running -dataex qa02-. Copy Stata's output from that command here into the Forum following the instructions from -help dataex-. Only with that will it be possible to solve your problem.

      I cannot emphasize enough the importance of using -dataex- here. Do not post a screenshot of the Browser, nor another image of -list- or -tab- output: that will be useless.
      Thank you, Clyde. Here is the dataex output.
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input long qa02
      -1279
      -5631
       9709
       2070
       -426
      -3958
       2830
      -7305
       3378
      -2801
        425
        731
      -1370
      -1583
      -4932
       3257
      -1918
       8735
       2251
       7640
      -4231
      10379
      -3986
      -4048
        244
      -7427
       8248
      -1126
       6453
       9375
       -457
       1947
      -7639
       2616
       8491
       5844
      -2283
      -3897
        -31
      -1064
      -3805
       2922
       4322
       2282
       9921
      -4231
         31
       4049
      -2160
       8340
      -4048
       7944
       8521
       -730
      -7366
      -5205
       3013
       3622
      -6758
      -1430
      -2040
      -7184
       1674
      -7701
      -6605
      -7519
      -7274
      -4717
      -6454
       7487
      -7976
       1308
      -7731
      -6666
       -153
       4352
       2192
       7336
      -7214
       -883
      -5509
       1247
       7944
       6848
       -822
       4596
       1917
      -5875
       7610
      -8341
        821
       2769
       -457
      -3836
       -791
      -5509
       1065
      -1614
       -610
       -914
      end
      format %tdD_m_Y qa02
      ------------------ copy up to and including the previous line ------------------

      Listed 100 out of 10151 observations
      Use the count() option to list more

      .

      Comment


      • #4
        Thanks for the data example

        Code:
        gen year = year(qa02)

        Comment


        • #5
          Originally posted by Nick Cox View Post
          Thanks for the data example

          Code:
          gen year = year(qa02)
          It works. Thank you, Nick!

          Comment

          Working...
          X