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

select_multiple fields can result in too many variables #14

Open
matthew-white opened this issue Jun 2, 2014 · 0 comments
Open

select_multiple fields can result in too many variables #14

matthew-white opened this issue Jun 2, 2014 · 0 comments

Comments

@matthew-white
Copy link
Collaborator

odkmeta splits select_multiple variables, with the number of new variables equal to the number of choices of the associated list. This ensures that the datasets created by the odkmeta do-file always have the same number of variables, regardless of what the data looks like. This is usually what you want, but if a list has many choices, it may be better to create only as many variables as are absolutely needed, in order to minimize the number of variables in the datasets.

To do this, replace the following code in the odkmeta do-file:

capture confirm numeric variable `var', exact
if !_rc {
    local parts
    local next 1
}
else {
    split `var'
    local parts `r(varlist)'
    local next = `r(nvars)' + 1
    destring `parts', replace
}

forvalues i = `next'/`nparts' {
    local newvar `var'`i'
    generate byte `newvar' = .
    local parts : list parts | newvar
}

with this:

capture confirm numeric variable `var', exact
if !_rc {
    generate byte `var'1 = .
    local parts `var'1
}
else {
    split `var'
    local parts `r(varlist)'
    local next = `r(nvars)' + 1
    destring `parts', replace
}
local nparts : list sizeof parts

I'm hesitant to make this an actual option, as it's such an easy fix, but perhaps we could add these instructions to the help file. @internetlindsey, thoughts?

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

No branches or pull requests

1 participant