Announcement

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

  • Insertto or appendto

    Dear Stata list,

    I want to generate an error list in a dta file on different conditions for data cleaning. I have searched the command like insertto or appendto but did't find any help in this regard.

    for example:

    bys hhid: appendto <varlist> if _n > 1 , using errors.dta comment("Duplicates")
    bys hhid: insertto <varlist> if _n > 1 , using errors.dta comment("Duplicates")

    appendto <varlist> if condition , using errors.dta comment("var1 = 1 and missing(var2)")

    I know this can be done via post file after marking such records or using preserve/restore. It would be helpful if this could be done with just one command.

    Thanks
    Rasool Bux

  • #2
    Some quick thoughts this morning. I don't believe there's a single command that does exactly what you want. -frame put- or -append- can get you close if you don't mind intermediate frames/files. If you've just got a few error conditions to look for this is a reasonable and efficient approach.

    Alternatively, you can create a variable that flags errors. It can take zero as an initial value, signifying no error. Then, as errors are found, replace the value for those observations with a different value that indicates the type of error (e.g., 1=duplicate, 2=inconsistent values, etc.). When you've done checking, you now have a documented set of errors, the full observations that caused them, and can easily dump them into a error-only dataset. You will just adjust your error checking code to ignore values that already have an error code identified.

    Comment

    Working...
    X