Announcement

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

  • Transforming Missing String Observations (.d) to Numerical Missing Observations

    Hi, All:

    I am not sure how to transform my missing string observations (e.g. .d, .r) to numerical missing observations. Can someone help me? I want to do this so I can drop these as numerical observations in a listwise deletion. (I already know how to do a listwise deletion.)

  • #2
    You need to show an example of your data. I can't tell from your explanation whether you have a string variable that includes values like ".d" and ".r" or if you have a numeric variable that includes some of Stata's extended missing values such as .d and .r.

    To show data examples, please use the -dataex- command. If you are running version 15.1 or a fully updated version 14.2, it is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      My apologies.

      Here is my data.


      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float age byte(asian black daysdrunk depress exercise friends hispanic hrstv numdrinks relig sex unfrndly white)
      16.8333 0 1 .s 6 1 1 0 20 .s 17 2 0 0
      15.1667 0 0 3 19 2 2 0 12 3 0 1 0 0
      18.1667 0 0 4 12 2 3 0 6 6 5 1 0 1
      15.1667 0 0 .s 6 1 3 1 30 .s 22 2 1 0
      16.8333 0 0 .s 17 1 1 1 5 .s 22 1 1 0
      19.8333 0 1 5 20 1 3 0 22 2 .r 2 0 0
      17.8333 0 1 1 16 1 1 0 20 2 0 2 0 0
      18.3333 0 0 2 15 3 3 0 3 4 0 2 0 1
      13.6667 0 0 3 14 1 2 1 5 3 22 2 0 0
      13.9167 0 0 .s 14 3 2 0 15 .s 19 2 1 1
      16.1667 0 0 4 3 1 3 0 3 1 0 1 0 1
      16.9167 0 1 .s 22 2 1 0 2 .s 11 1 0 0
      17.4167 1 0 .s 7 0 3 0 10 .s 0 1 0 0
      19.0833 0 0 .s 15 0 3 0 8 .s 14 1 0 1
      18.5833 0 0 2 20 2 3 1 3 3 4 2 1 0
      17 0 0 6 15 2 3 0 75 22 14 1 0 1
      17.5833 0 0 3 3 2 3 0 7 1 5 1 0 1
      16.75 0 0 1 5 3 3 0 6 1 5 2 1 1
      13.5 0 0 .s 8 1 2 0 28 .s 4 2 0 1
      14.0833 0 1 .s 9 1 1 0 50 .s 16 2 0 0
      18.25 0 0 .s 6 3 3 0 10 .s 5 2 0 0
      16.5 0 0 3 5 2 2 0 1 5 14 2 0 1
      17.1667 0 0 .s 9 1 1 1 30 .s 22 1 0 0
      14.3333 0 0 1 7 3 2 1 35 7 22 2 0 0
      17 0 1 .s 6 3 2 0 20 .s 4 1 0 0
      14.9167 0 1 .s 13 1 1 0 40 .s 4 2 1 0
      17.0833 0 0 1 22 0 0 0 5 2 14 2 1 1
      15.5833 0 0 2 0 0 3 0 15 6 5 1 0 1
      17.9167 0 0 2 9 1 1 0 12 3 7 2 0 1
      18.25 0 0 .s 9 3 1 0 4 .s 10 1 1 1
      18.75 0 1 2 10 3 1 0 4 1 .r 1 0 0
      16.5 0 0 .s 31 1 3 0 7 .s 4 2 3 1
      18.1667 0 0 4 16 3 3 0 10 10 22 2 0 1
      13.9167 0 0 .s 4 0 2 0 49 .s 13 2 0 1
      18.1667 0 1 1 5 1 2 0 30 2 4 2 0 0
      16.6667 0 0 4 6 1 3 0 14 5 19 2 0 1
      13.75 0 1 1 2 1 3 0 28 1 4 1 0 0
      14.25 0 0 .s 3 3 1 0 11 .s 12 1 0 1
      13 0 0 .s 0 3 2 0 14 .s 19 2 0 0
      14.25 0 0 .s 5 3 2 0 4 .s 13 1 0 1
      12.9167 0 0 .s 2 3 1 0 5 .s 22 2 0 1
      14.75 0 0 .s 21 0 1 0 10 .s 14 2 1 0
      19.0833 0 0 3 25 2 3 0 10 7 0 1 1 1
      16.4167 0 0 2 11 1 1 1 4 2 22 2 0 0
      17.4167 0 0 .s 24 2 0 0 20 .s 0 2 0 1
      15.1667 0 1 .s 3 3 1 0 8 .s 5 1 0 0
      14.0833 0 1 .s 0 3 3 0 6 .s 18 1 0 0
      15.75 0 0 .s 7 1 2 0 10 .s 0 1 0 1
      15.0833 0 1 .s 0 3 2 0 5 .s 5 2 0 0
      15.3333 0 0 .s 9 3 2 0 28 .s 17 1 1 1
      17.1667 0 0 .s 10 2 3 0 20 .s 4 1 1 1
      15.1667 0 0 .s 8 3 3 1 5 .s 12 1 0 0
      13.75 0 0 .s 6 3 2 0 35 .s 28 1 0 1
      13.6667 0 0 .s 6 0 2 0 40 .s 4 1 0 1
      17.3333 0 0 .s 6 2 2 0 15 .s 5 2 0 0
      13.25 0 0 .s 7 1 1 0 35 .s .d 2 0 1
      17 1 0 1 8 1 3 0 21 2 22 2 0 0
      17.25 0 0 1 6 3 1 0 20 3 13 1 0 1
      13.25 0 0 .s 9 2 1 0 24 .s 5 1 2 1
      17.8333 0 0 4 15 2 3 0 24 15 4 2 1 1
      18 0 0 2 7 3 3 0 2 6 22 1 0 1
      15.0833 0 1 .s 2 3 1 0 24 .s 4 2 0 0
      14.3333 0 1 2 3 3 1 0 4 2 4 1 0 0
      17.75 0 0 4 17 2 2 0 6 3 28 1 1 0
      18.4167 0 0 .s 34 0 3 0 2 .s 0 2 1 1
      13.25 0 0 1 17 3 2 0 21 7 5 2 0 0
      16.9167 0 0 5 16 0 2 0 35 3 16 2 0 1
      16.6667 0 0 .s 9 3 3 1 3 .s 16 1 0 0
      16.5 0 1 .s 15 2 1 0 50 .s 10 1 1 0
      16.8333 0 1 .s 10 3 2 0 10 .s 0 1 1 0
      13.5 0 0 .s 18 1 0 1 40 .s 22 2 0 0
      16.25 0 0 1 6 3 2 0 4 2 16 2 0 1
      15.1667 0 0 .s 3 2 3 0 7 .s 4 1 0 1
      17.0833 0 0 4 6 1 3 0 35 2 4 1 0 0
      15.5833 0 1 1 13 1 2 0 8 8 4 2 0 0
      16.4167 0 1 .s 5 2 1 0 15 .s 4 1 0 0
      16.25 0 0 2 10 3 3 0 14 15 0 1 1 1
      17.75 0 0 3 6 0 3 0 5 8 22 1 0 1
      17 0 0 2 15 2 3 0 24 3 0 1 0 1
      17.1667 0 1 1 35 3 1 0 42 5 0 1 1 0
      17.3333 0 0 4 10 3 3 0 20 12 4 1 1 1
      13.0833 0 0 .s 11 1 2 0 17 .s 27 1 0 1
      16.75 0 0 3 13 1 1 0 21 3 4 2 0 1
      17.4167 0 0 .s 9 1 2 0 3 .s 4 2 0 1
      15.5 0 1 .s 2 2 2 0 40 .s 14 1 0 0
      17.5833 0 0 .s 7 0 1 1 14 .s 22 1 0 0
      16.1667 0 0 .s 6 0 1 1 40 .s 22 1 0 0
      15.8333 0 0 .s 12 2 1 1 3 .s 22 1 0 0
      14.75 0 0 1 13 0 2 1 40 1 22 1 0 0
      15.5 0 1 .s 24 2 3 0 99 .s 0 2 1 0
      16.5833 0 0 .s 18 1 3 1 10 .s 22 2 0 0
      16 0 0 1 13 1 2 0 5 1 22 2 0 1
      18.75 0 0 .s 10 3 3 0 3 .s 0 2 0 1
      15.8333 0 0 4 6 2 3 0 8 6 14 1 0 1
      13.75 1 0 1 4 3 2 0 25 1 22 2 0 0
      14.6667 0 0 .s 1 0 1 0 5 .s 14 1 0 1
      14.0833 0 0 .s 27 0 0 0 40 .s 13 2 3 1
      14.9167 0 1 .s 34 1 3 0 24 .s 4 2 0 0
      14.6667 0 0 .s 8 3 2 0 3 .s 19 1 0 1
      16.8333 1 0 2 10 1 3 0 8 5 5 2 0 0
      end

      Comment


      • #4
        So, all the variables are numeric. I bet the variables are assigned formats that specify what .s and .d mean. You can format the values of a numeric variable - I do this all the time with factor variables so that when I use -estout- (Ben Jann, available on SSC), the values for race will display as "White", "Black", etc, rather than 0, 1, etc. When you tabulate a numeric variable, you'll see the extended missing values (i.e. .a through .z) displayed in text, but they are not strings. They are treated as missing by regression commands.
        Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

        When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

        Comment


        • #5
          The data example you show would suggest that you do not have any string variables. What has confused you here, I suspect, is that Stata allows users to represent missing values with anything in the following set: ., .a., .b, .c ..., .z. Stata does not actually store these values as strings. It just displays them that way. Reading -help missing- would clarify some of this for you, I suspect. What you have (or at least what you have shown) are all numeric variables, with .r and .s used to represent missing values.
          I also think you misunderstand about deletion: Stata, when performing a statistical analysis, will automatically ignore (not actually "delete") observations that are missing on any variable used in that analysis. You're not the one that would have to know how to "delete" them (listwise or pairwise or whatever), but rather Stata would do that. And, if you are thinking to actually delete them from your data set, I wouldn't recommend that.

          Comment

          Working...
          X