Announcement

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

  • error r(198) Failed to Compute When Running levelsof Command

    Hello, Statalist-ers,


    I have a balanced panel dataset of census tract-year observations with variables on select socioeconomic variables.

    I need to use the "built-in" macro r(levels) from the levelsof command in an imputation process for each census tract, but when I run the command on the unique identifier for census tract (i.e., a string variable containing its geocode), I get the 'failed to compute' error with no additional details. In looking around, I found this post in which the programmer is said to have discovered a bug in the underlying .ado file for the collapse command. Similar to the linked post, the command seems to work properly for the year variable, which has far fewer unique values.

    The exact command I'm running is
    Code:
     levelsof geocode
    .


    Curious if anyone has experienced this behavior or if they have suggestions on how to fix?

    Thanks,

    Kelsey
    Last edited by Kelsey OHollaren; 21 Aug 2024, 17:40. Reason: added tags

  • #2
    -help levelsof- indicates that "levelsof may hit the limits imposed by your Stata. However, it is typically used when the number of distinct values of varname is not extremely large." There over 70,000 census tracts in the U.S., so I suspect this is your problem. If you just need to do something on each tract, I'm not sure why you need -levelsof-. What about something as simple as:
    Code:
    bysort geocode: -- DoWhatever--
    or
    Code:
    egen numgeo = group(geocode)
    summ numgeo, meanonly
    forval i = 1/`r(max)' {
        -DoWhatever- if `i' == numgeo
    }
    If this won't help, post back and explain.

    Comment


    • #3
      Much better approach. Thanks, Mike.

      missed that note in the documentation re: limits on number of unique observations.

      Comment

      Working...
      X