Announcement

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

  • string to missing

    hi everyone! I have a small dataset of perceptions, likert scale. the thing is some answer are "na" meaning for do not apply. I want to encode this variables as missing but I get a type mismatch. Here is my code: foreach x of varlist s1p3 s1p6 s2p1 s3p6 s3p8 s3p11 s4p3 s4p5 s4p7 s5p* s6p1 s6p3 s6p4 s6p5 s6p6 s6p7 s6p8 s6p9 s6 > p10 s6p11 s6p12 s6p13 { 2. replace `x'="" if `x'=="NA" | `x'=="n/a" | `x'=="Pend" | `x'=="N/A" 3. destring `x', replace 4. } (1 real change made) s1p3 has all characters numeric; replaced as byte (1 missing value generated) (1 real change made) s1p6 has all characters numeric; replaced as byte (1 missing value generated) I would very much appreciate any help

  • #2
    That's pretty much unreadable. Please edit or repost the question with readable code using CODE delimiters.

    The advice at http://www.statalist.org/forums/help#stata should take 2 minutes to learn.

    Comment


    • #3
      Beyond Nick's recommendation, the results you posted do not seem to show any indication of a type mismatch. You should repost including enough of your output to show where the type mismatch occurred. It may help if you try a shorter variable list, if it's at all obvious what variable caused the type mismatch.

      Comment


      • #4
        The advice and request to reformat this was ignored, but to follow up William's good advice I note that the loop will fail with the reported error if (and I believe only if) one of the following variables is numeric:

        Code:
        s1p3 s1p6 s2p1 s3p6 s3p8 s3p11 s4p3 s4p5 s4p7 s5p* s6p1 s6p3 s6p4 s6p5 s6p6 s6p7 s6p8 s6p9 s6p10 s6p11 s6p12 s6p13
        I guess it's s2p1 which triggers the error, as there is no signal from destring s2p1

        Comment


        • #5
          "one" should be "any"; the loop will fail at the first encountered in any case.

          Comment

          Working...
          X