Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistently importing string fields as string #16

Open
matthew-white opened this issue Jun 4, 2014 · 1 comment
Open

Consistently importing string fields as string #16

matthew-white opened this issue Jun 4, 2014 · 1 comment

Comments

@matthew-white
Copy link
Collaborator

Request over e-mail:

When the odkmeta generated do-file creates the stata dataset, it is inconsistently generating the same variable as both string and byte for different version of the survey.

For example, if there are no observations for a text variable in one version of the survey, the text variable is generated as a byte. In another version of the survey where is there is an observation, it is correctly generated as a string. This is creating problems when we try to append the survey versions for a compiled dataset.

Do you know why this is happening? And, is there a way to fix this with the command, or will it require editing the code in the do-file?

@matthew-white
Copy link
Collaborator Author

I think a reasonable enhancement would be to convert string fields imported as numeric back to string.

The following code could be added almost anywhere in the .dta loop, e.g., before select_multiple fields are split:

local strvars
local strtypes text audio image video
ds, has(type numeric)
if "`r(varlist)'" != "" ///
    ds `r(varlist)', has(char Odk_type)
foreach var in `r(varlist)' {
    loc type : char `var'[Odk_type]
    if `:list type in strtypes' | `:char `var'[Odk_is_other]' ///
        local strvars : list strvars | var
}
if `:list sizeof strvars' {
    tostring `strvars', replace format(%24.0g)
    foreach var of local strvars {
        replace `var' = "" if `var' == "."
    }
}

Not sure about the list of ODK string types. @internetlindsey?

We should also make a note in the help file about issues that insheet could introduce here. E.g., we could not distinguish the string value "1" from "01".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant