Announcement

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

  • "__000001 not found" message when running command on dataset with no observations

    Dear Statalisters,

    I have searched in Stata list and do not believe that this has been covered specifically. Apologies in advance if it has.

    I have several hundred files which I am running commands on in a looped command in Stata 14 (updated).

    In a section of the commands, the error message

    __000001 not found
    r(111);

    was given. This was when the commands were run for a file with no observations. The looped command worked fine for files with observations.

    I also ran the same commands in this same specific file, not in a loop, and discovered that it occurred when I ran an egen command (by patid: egen onlyalcdata = min(alccodes) if patid !=.).

    I tried putting the capture command in front of this and other commands, but this does not seem to have solved the problem. In the case of this specific command, capture cannot be combined with by.

    I would be grateful for any help in ways to allow stata to run a looped command to run across files, even if it has no observations, or if the looped command has sub-commands that would otherwise generate this error mesage.

    Thank you in advance for your expert advice.
    Last edited by Abdul-Kareem Abdul-Rahman; 08 Aug 2016, 01:55.

  • #2
    Insert a line of code to trap zero-observation datasets. Something like the following.
    Code:
    foreach file in <several hundred files> {
        use `file', clear
        if _N == 0 continue // <= here
        <commands>
    }

    Comment


    • #3
      Seems to have worked!

      Thank you so much.

      Comment


      • #4

        Hello Joseph,
        I do not understand on how to use the mini program above , can you give an example of how to use it ? I have a similar situation.
        Thank you so much.
        Last edited by Alexandra TD; 20 Jun 2024, 15:08.

        Comment


        • #5
          The OP in #1 was specific that the error was caused by lack of observations in certain files.

          This was when the commands were run for a file with no observations.
          _N is the observation count. So the code handles this by imposing the following condition if the observation count is zero.

          if _N == 0 continue // <= here
          We do not know what your issue is. Provide a reproducible example if the advice in this thread is not useful.

          Comment

          Working...
          X