Announcement

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

  • Getting Stata to recognize . as a missing value in string variables

    I have a dataset with multiple string variables. In my dataset, usually only males or females answer a given question, so there are often many missing values within a variable column. I put a period in each cell that doesn't have an answer because I wanted Stata to recognize it as "missing." However, instead, it just recognizes it as a string. I also had these cells as blank before (""), but it was doing the same thing. How can I make it so that the periods are not included (i.e. in the below table, only 262 instances would be recognized in the frequency count.

    I completely understand that this is very simple, but as somebody who is just getting started with Stata, it has been a real struggle to figure out. Can anybody help?

    -Bri




  • #2
    Your attachment, whatever it is, is unreadable. Please use your full real name as requested in the FAQ Advice, e.g. "Brian Hutchinson".

    Code:
    ds, has(type string)
    
    qui foreach v in `r(varlist)' {
        replace `v' = "" if trim(`v') == "." | trim(`v') == ""
    }
    Note that explicit spaces don't count as missings. Only empty strings do. The code above should fix both your problems.

    (The answer to the title is: You can't do that.)
    Last edited by Nick Cox; 18 Dec 2014, 03:47.

    Comment


    • #3
      Wow! Thank you so much Nick. That worked perfectly. Very much appreciated. - Brian Hutchinson

      Comment


      • #4
        Good. And I guessed your name correctly. Now please use the "Contact us" button at bottom right to contact the forum administrators to request an identifier change.

        Comment

        Working...
        X