Categorical Question String Value

It would be extremely useful if categorical question could be enhanced to use string values (currently integers only) to accommodate special generated codes. This would eliminate the need to create a repository outside of Survey Solutions to match codes to numeric values.

Could you be a bit more specific?
Perhaps, what is the survey? Question? Particular categories?

An example would be the Standard Industrial Classification (SIC) codes as well as Standard Occupational Classification (SOC) for usage in a survey for Labor Force. A number of the codes are defined with leading zeros which are striped when converted to integer.

Also an abstract example, if a category contains an alphanumeric codes it would not be possible to include it in the dataset until after export and further processing is carried out.

If the variable type of the categorical value could be define as string it would reduce the need to merge data sets after export.

So how do you subsequently define labels for these codes in Stata or SPSS if 7 and 07 are different categories?

I usually solve this by creating a string variable with a definition similar to this:
SICCode.ToString().Length == 7 ? String.Join("", "0",SICCode.ToString()): SICCode.ToString()

I would like it to be possible to get the text corresponding to the code in categorical questions, for example:
Variable: gender
code description
1 Male
2 Female

Then I would like can do some like this: gender.Text or gender.Code

  1. @kv700032, simplify:
    SICCode.ToString("00000")
    Put as many zeros as you want the code to be wide.

  2. But this is only when there are no collisions of e.g. β€œ7” and β€œ07” to mean different things. Whether these are possible or not, @jsmallhorn should inquire with the source of those nomenclatures.

  3. The result is a string, which is not allowed to have labels in Stata.

  4. Clearly, if this is possible, then we can just format the representation of the code in the statistical package, for example in Stata:

format varname %05.0f

As in the following example:

clear
set obs 3
gen SICCode5=_n
format SICCode5 %05.0f
list, clean

       SICCode   SICCode5  
  1.         1      00001  
  2.         2      00002  
  3.         3      00003  

  1. I don’t understand what you meant by β€œif a category contains an alphanumeric codes it would not be possible to include it in the dataset until after export and further processing is carried out.”
2 Likes

@sergiy I tried but it doesn’t work.

This one works: 754.ToString("0000000")
Resulting in output: 0000754

Hence the problem is in that what you are converting is a nullable value (question).
Just take: CCIFHCon8Digitos.Value.ToString("00000000")

2 Likes

This one works, thanks for the explanation.