Announcement

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

  • Deleting blank cells across string variables

    Hi. I have three string variables with observations that are empty cells/missing across all three. I want to delete only observations that are empty across all three of the variables. I've tried two versions of the code (below), both of which don't work: 1) dropping observations that have missing entries across all three variables; 2) replacing the missing/blank with a "." value.

    Code:
    1) bysort id: drop if varA == " " & varB == " " & varC == " "
    
    2) local X "varA varB varC"
    
    foreach x of local X {
         replace `x'=. if missing(x) 
         }
    Any help would be much appreciated

  • #2
    What you need to know is that missing string values are
    Code:
    ""
    which is a string of length zero, rather than
    Code:
    " "
    which is a string of length 1 containing a single blank character.

    So
    Code:
    drop if varA == "" & varB == "" & varC == ""
    should do what you want.

    Comment


    • #3
      Thank you, William. That did solve the problem.

      Comment

      Working...
      X