Announcement

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

  • String variables with value labels!!

    As far as I understand string variables cannot have value labels. However, I have received a dataset with string variables which shows (output of -describe- command) that the string variables have value labels attached to them. Moreover, the value labels have two or more different labels (texts) attached to the same value 0 (while the variables have no zero values). Could anyone share any thought about what might be going on here? Or have any of you encountered this problem ever? I am sharing my code and its output below (I cannot even understand how to give a data example in this context as I do not know how to create string variables with value labels, so pardon me.) Note that the problem remains the same even if I save the data in the newer dta format 118.

    Code:
    . use "D:\L02_Demographic_particulars.dta" 
    
    . version
    version 19.5
    
    . dtaversion "D:\L02_Demographic_particulars.dta"
      (file "D:\L02_Demographic_particulars.dta" is .dta-format 115 from Stata 12)
    
    . describe Sector Gender
    
    Variable      Storage   Display    Value
        name         type    format    label      Variable label
    --------------------------------------------------------------------------------
    Sector          str1    %-9s       Sector0    Sector
    Gender          str1    %-9s       Gender2    Gender
    
    
    . label list Sector0 Gender2
    Sector0:
               0 urban
               0 rural
    Gender2:
               0 Female
               0 transgender
               0 Male
    
    . tab Sector
    
         Sector |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              1 |    292,208       62.63       62.63
              2 |    174,319       37.37      100.00
    ------------+-----------------------------------
          Total |    466,527      100.00
    
    . tab Gender
    
         Gender |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              1 |    240,556       51.56       51.56
              2 |    225,897       48.42       99.98
              3 |         74        0.02      100.00
    ------------+-----------------------------------
          Total |    466,527      100.00





  • #2
    Well, it's anybody's guess how this data set came to be. My guess is that it was originally created for a different application that does support value-labels on string variables. I think, for example, that SPSS does support that. If this is what happened, one might wonder whether these invalid value labels also show 0 for every value in the original source, of whether they might have been introduced by whatever program translated the data set into Stata.

    It is fortunate that, at least in the -tab- command these labels are ignored, because the labels themselves always show 0 for the numeric value. Have you tried -summarize-? If everything is working well, -summarize- should show a count of 0 and missing values for the other statistics: that is what -summarize- does with string variables.

    Even if it seems to behave well with calculations, I would not work with this data set as is. It's too risky that some command might mess up and use the labels in some unpredictable way. I would -label drop- both of those labels. Then, I would -destring- the variables. And then, if you would like to properly label the numeric variables thereby created, go ahead and do that. Be sure to preserve the original data set, but save the one you fix up under a different name.

    You might also contact the source of the original data set and ask them how it was created.
    Last edited by Clyde Schechter; 31 Jul 2026, 15:15.

    Comment


    • #3
      Prof. Schechter, thank you for your reply.

      I think your guess about SPSS to Stata conversion is the correct answer to my question. This data is supplied by the National Sample Survey office of India. Long ago they used to make the public use data available in Fixed Format files and I was comfortable with those files. Then they changed to NESSTAR and now very recently they have changed to giving the datasets out in CSV, JSON, SPSS, SAS, and Stata formats separately. Most likely they created the data in SPSS format and then just converted them to the other formats. I do not have access to SPSS at this moment, so cannot do the check that you suggested. I shall try my luck tomorrow at my University library.

      The outputs of -summarize- are behaving exactly the way you said it should with these variables (0 under Obs and missing for the rest of the output). So they are string variables nonetheless.

      I shall also cross check the conformity of the CSV formats with these Stata format files. And most likely work with the CSV version anyway.

      Comment


      • #4
        If you want a free, open-source, and somewhat limited version of SPSS, consider GNU PSPP at https://www.gnu.org/software/pspp/
        David Radwin
        Senior Researcher, California Competes
        californiacompetes.org
        Pronouns: He/Him

        Comment

        Working...
        X