Announcement

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

  • destring, force

    Hello,
    I am using destring, force in Stata 13. The log file informs me the total number of missing values generated. So, as my dataset contains empty cells, it includes those in the total number of missing values generated. How could I get the number of string variables that have been converted to missing values (total number of missing values generated except those from empty cells)?

    Thank you!

  • #2
    So if your string variable is called x, the number of missing values generated other than from empty cells would be gotten with:
    Code:
    count if missing(real(x)) & !missing(x)
    But really, using the -force- option on destring is not a good idea unless you are absolutely sure why those non-numbers are sitting there in the midst of what you expect to be a numeric variable. You may be misunderstanding your data, or throwing away information that is important. It's much better to do

    Code:
    list if missing(real(x)) & !missing(x)
    before running -destring- and inspect those to see what they are and understand how they got there.
    Last edited by Clyde Schechter; 06 Jun 2015, 22:02.

    Comment


    • #3
      Thank you, Clyde! I have a lot of variables which should be numeric with very few string values. So, it won't be a problem dropping those string values, the big problem is that I need to get this net missing values generated for a lot of variables, so I need something more automatic, though I cannot create more variables with the ex ante missing values to compare with the ex post ones and then get the difference. Any suggestion of sth more automatic without turnning my dataset bigger?

      Comment


      • #4
        About your first suggestion: when I type -count if missing(real(x))-, I get the r(109) error.

        Comment


        • #5
          Sorry about my last answer, I tried with ir for a numeric variable and then it didn't work, as expected! Let me know if you have any other suggestions for a more automatic way to get those net missing values generated.
          Thank you again!

          Comment


          • #6
            Code:
             
            help foreach 
            
            
            ds, has(type(string)) 
            
            foreach v in `r(varlist)' { 
                  di "`v'{col 33}" _n 
                  count if missing(real(`v')) & !missing(`v') 
            }

            Comment


            • #7
              Thank you very much, Nick! I just had to drop a parentheses in the ds command and it worked!
              ds, has(type string) Just for curiosity: what does {col 33} stands for? I tried with and without is and had the same output.

              Comment


              • #8
                You are correct on the syntax of ds. {col 33} forces the display to move to column 33. See the help for smcl.

                Comment


                • #9
                  Thanks, Nick!

                  Comment

                  Working...
                  X