The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Topics » Fertility » tfr2 report error: variable __000005 not found (Stata tfr2 error)
tfr2 report error: variable __000005 not found [message #31949] Tue, 11 August 2026 23:41
chen_samulsion is currently offline  chen_samulsion
Messages: 1
Registered: August 2026
Member
Dear members,

I am experiencing persistent errors when trying to use the tfr2 command (from SSC) to plot age-specific fertility rates (ASFR) with confidence intervals. I would greatly appreciate any insights or suggestions.

Background
I am working with a dataset of 38,167 women that I converted from person-year format to wide-format birth history data (following the standard DHS-style structure with variables b3_01 through b3_09 storing birth dates in CMC format). I am using Stata 16.0 on Windows.

The Problem
The tfr2 command itself works perfectly for obtaining estimates. For example, this runs without any issues:

stata
tfr2, len(3) trend(1) age(5) mina(15) maxa(49) bvar(b3_*)
Output (abbreviated):

text
ASFRs and TFR (average over the period)
------------------------------------------------------------ ------------------
events | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+---------------------------------------------- ------------------
Rate_1519 | .0052696 .0006803 7.75 0.000 .0039363 .006603
Rate_2024 | .1222314 .0028996 42.15 0.000 .1165483 .1279145
...
TFR | 1.28647 .0193641 66.44 0.000 1.248517 1.324423
------------------------------------------------------------ ------------------
However, when I try to use the gr or se options to generate plots or confidence intervals, I get errors:

stata
tfr2, len(3) trend(1) age(5) mina(15) maxa(49) bvar(b3_*) gr
text
variable __000005 not found
r(111);


What I Have Tried
Checking variable names: My birth history variables are correctly named b3_01 through b3_09.

Running the latest version: I have the most recent version of the tfr2 package installed (ssc install tfr2, replace).

Tracing the error: With set trace on, I traced the execution and found that the error occurs when xi tries to create dummy variables from a temporary variable __000005 (which appears to be the age group variable generated by tabexp). The unabbrev command fails because the temporary variable no longer exists in the context where xi is called.

Inspecting the source code: Looking at tfr2.ado, the issue seems to be that occurred in Trend Model part.
*-----------------------
*-------- Trend model***
*-----------------------


if `trend'<`length' {


if "`cluster'" == "" {
quietly : xi, prefix(_A) i.`age_g'
local Age _A*
if `agemax'==`agemin' {
local Age ""
}
quietly : xi: poisson events `Age' i.`period', exposure(`exposy') level(`level')

}


My Questions
Has anyone else encountered this issue with tfr2? Is this a known bug?

Are there any workarounds that don't involve modifying the source code?

If modifying the source code is the only solution, what would be the correct way to fix this? I noticed that changing tempvar level2 z to local macros didn't help, because the root cause appears to be deeper in the xi command interaction.


Additional Information

Data: 38,167 observations, birth history variables b3_01-b3_09

The tabexp command works perfectly and produces the expected output

Thank you in advance for any guidance you can provide. I am happy to share more details or code snippets if needed.

Best regards
  • Attachment: 077.png
    (Size: 100.68KB, Downloaded 44 times)
  • Attachment: 922.png
    (Size: 70.90KB, Downloaded 53 times)
Previous Topic: Fertility and education
Goto Forum:
  


Current Time: Tue Sep 15 01:52:09 Eastern Daylight Time 2026