Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Odkmeta import do file invalid syntax error importing attributes as characteristics

    I used Kobotoolbox and am now trying to get my data into STATA using odkmeta. I’ve gotten pretty far, but now I’m getting an error when I run the import do file odkmeta created when it gets to my first variable with a text response (the first “please specify other”).

    Here is the section of the do file that precedes the error:
    * Import ODK attributes as characteristics.

    insheet using "mydata.csv", comma nonames clear
    local fields
    foreach var of varlist _all {
    local field = trim(`var'[1])
    assert `:list sizeof field' == 1
    assert !`:list field in fields'
    local fields : list fields | field
    }

    insheet using "mydata.csv", comma names case clear
    unab all : _all

    This runs fine, as do all the first several variables with numeric code responses. But then when I get here:
    * caregroup_promoter_other
    * Duplicate variable name with o_prefill_codes-caregroup_promoter
    local pos : list posof "o_prefill_codes-caregroup_promoter_other" in fields
    local var : word `pos' of `all'

    I get invalid syntax after this last command.

    Any help figuring this out would be much appreciated!

    -Kate


  • #2
    I'm not familiar with Kobotoolbox or odkmeta, so there may be something about this context that I'm overlooking. But just from a general Stata perspective, I see a potential problem with
    Code:
    local var : word `pos' of `all'
    First, local pos is defined in the preceding command as the position of "o_prefill_codes-caregroup_promoter_other" in local macro fields. But if that string doesn't actually occur in local macro fields, then pos will be 0, and an attempt to evaluate word 0 of a macro is a syntax error.

    So, I would -display `"`fields'"' before that final command to see what's in there. If it doesn't contain "o_prefill_codes..." then that's the immediate cause of your problem. You'll then need to chase down why it isn't there. The elements of local macro field are extracted from the first observation in mydata.csv, so you should look there. I think you'll find that it isn't there. Then you will have to chase back how mydata.csv was created to find out why not.

    Comment


    • #3
      Thank you so much Clyde! This is so helpful! The first observation of that column is a name and was entered in by the enumerator. Is it possible there is something required to address the rack that this is a string variable?

      I'm a relative STATA novice, so I really appreciate the help!

      Comment


      • #4
        Well, the code you showed explicitly treats all of the variables as string variables already. So I don't think that's the issue. I don't know what you mean by "the enumerator." I suppose that is something in Kobotoolbox, about which I know nothing. (I never even heard of it before.) You might want to contact the developers/vendors of Kobotoolbox about this problem.

        Comment


        • #5
          Thanks Clyde. Enumerator was the interviewer who collected the data - they typed it in. But I'm finding that this error is happening with all the local macros coded this way. I'll have to look into it further with people who understand the difference between how the Kobo server and the ODK server export the data. That seems to be the heart of the problem since the do file was written by a program intended for data downloaded from ODK Aggregate.

          Thanks again for trying to help!

          Comment

          Working...
          X