Announcement

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

  • How to remove value labels from string variable (problem with -usespss-)?

    The Stata module -usespss- from SSC can be used to read SPSS files into Stata. SPSS allows value labels for string variables and -usespss- retains those labels, although they are not allowed in Stata.

    How can value labels be removed from a string variable? The command that is normally used to remove labels from a variable yields an error message with string variables. In the example below, "stringvar" is a string variable with attached value labels.

    . lab val stringvar .
    may not label strings
    r(181);

  • #2
    Try label drop.

    Comment


    • #3
      -label drop- doesn't detach the value label from the variable. After -label drop-, -d stringvar- still shows the value label.

      Comment


      • #4
        This is not a problem I have experienced but

        1. Do the ghost value labels do any harm? On the face of it, it's a weird Stata bug to allow them. Sergiy's probably writing .dta files in a way that Stata accepts but wouldn't write of its own accord.

        2. I would loop over your string variables something like this.

        Code:
        ds, has(type string)
        
        foreach v in `r(varlist)' { 
            tempvar work 
            gen `work' = `v' 
            drop `v' 
            rename `work' `v' 
        }
        and see if the value labels disappear. Also, see what clonevar does in place of generate.

        Comment


        • #5
          The ghost value labels do no harm per se but I am manipulating the labels in a large number of files that were originally in SPSS format and some of the commands stop with an error message if a string variable with a value label is encountered. To avoid the error message I had to build a variable type check into my loops but a more elegant solution would be to remove the value labels from string variables before subsequent processing.

          clonevar makes a copy but then shows an error message.

          . clonevar stringvarcopy = stringvar
          may not label strings
          r(181);


          However, the loop that you proposed works. I only added some commands to copy the variable label. Thank you, problem solved.

          Comment


          • #6
            Originally posted by Friedrich Huebler View Post
            -label drop- doesn't detach the value label from the variable. After -label drop-, -d stringvar- still shows the value label.
            Dear Friedrich, I am sorry for any inconvenience. You are probably right that there is no straightforward way to remove value labels of string variables since Stata does not allow there presence in the first place. Stata 13 added a few checks of the DTA files when they are open, but apparently not this check. My guess would be that -clonevar- would not transfer those value labels.
            The problem might be already fixed in the next beta version. At least I marked it as fixed as #5 of 2010 series of fixes.
            This page contains the necessary information: http://radyakin.org/transfer/usespss...espss_faq.html

            If possible, please tag the thread with tag usespss. Thank you, Sergiy Radyakin

            Comment

            Working...
            X