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

Option -relax- and un-insheet-able field names #19

Open
matthew-white opened this issue Sep 11, 2014 · 1 comment
Open

Option -relax- and un-insheet-able field names #19

matthew-white opened this issue Sep 11, 2014 · 1 comment
Labels

Comments

@matthew-white
Copy link
Collaborator

matthew-white commented Sep 11, 2014

Option relax specifies that the do-file ignore fields in the form that are not in the data; by default, it results in an error. However, it still results in an error for nonexistent fields with problematic (uninsheetable) field names, e.g., those whose Stata names are a duplicate with another field's. Currently option relax writes code to attach char metadata as follows:

local pos : list posof "field_name" in fields
local var : word `pos' of `all'
capture confirm variable `var', exact
if _rc ///
    local formnotdata `formnotdata' `var'
else {
    char commands...
}

Yet if `pos' == 0, :word results in an error:

. local var : word `pos' of `all'
invalid syntax
r(198);

Thus, the code should look more like:

local pos : list posof "field_name" in fields
if !`pos' ///
    local found 0
else {
    local var : word `pos' of `all'
    capture confirm variable `var', exact
    local found = !_rc
}
if !`found' ///
    local formnotdata `formnotdata' `var'
else {
    char commands...
}

The following also works. It's slightly less clean, as it adds an extra capture, but it's fine as a way to facilitate an easier find/replace for those wanting an immediate fix.

local pos : list posof "field_name" in fields
capture local var : word `pos' of `all'
if !_rc ///
    capture confirm variable `var', exact
if _rc ///
    local formnotdata `formnotdata' `var'
else {
    char commands...
}

On a final note, we shouldn't add `var' to `formnotdata' but rather the field name.

@matthew-white
Copy link
Collaborator Author

I think we may simply remove option relax in a future version, as it makes the code more complex and adds maintenance costs, and it shouldn't be needed when the submission data is compatible with the ODK Briefcase format (see #46).

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

No branches or pull requests

1 participant