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:
Then I would like can do some like this:
Put as many zeros as you want the code to be wide.
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.
The result is a string, which is not allowed to have labels in Stata.
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
- 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.”
@sergiy I tried but it doesn’t work.
This one works:
Resulting in output:
Hence the problem is in that what you are converting is a nullable value (question).
This one works, thanks for the explanation.