Announcement

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

  • How to get -keep- work even if a variable was not found

    Dear all,

    I am writing a routine which subsets a number of files and -append-s them to a longitudinal dataset. This means that the program first selects one file, takes a subset of it and then -append-s it to the longitudinal dataset. Some of these files might not have some of the variables I would like to -keep- even thoguh most of them have all variables. When I execute the program, it stops whenever one variable is not in the -using- dataset. Is there a way to avoid Stata to stop and get it -keep- only the available variables?

    Many thanks!
    Riccardo

  • #2
    It sounds like you want to use branching based on the results of code enclosed in capture blocks, or perhaps want to use the nostop option to do.

    Comment


    • #3
      Alternatively (since you didn't post the actual code ran), you *might* find it simpler to just do all your appends and then run keep. I *might* be wrong, but I think the normal thing for a simple append command to do when it encounters extra variables is to simply make the dataset wider and set all those cases w/out the extra variables to missing.

      Comment


      • #4
        Dear Stephen and Ben, thank you for your answers. Both strategies can solve the problem even though some of them can entail some risk. Accidentally, I got a valuable suggestion in another post where Phil Schumm suggests to create a local list containing the variables that I want and instersect that with the r(varlist) of the using database. I found that solution very easy to implement. You might want to check that out. All the best, Riccardo
        Last edited by Riccardo Valboni; 30 Jun 2014, 04:53.

        Comment

        Working...
        X