Announcement

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

  • Effects plot of results from causal mediation analysis error

    Hi all,

    I am working through a causal mediation analysis and attempted to plot effects of the results from the "mediate" command. Stata returned an error after running "estat effectsplot", suggesting that a temporary variable was not found:

    Code:
    variable __00000H not found
    I then went back to the Stata manual and attempted to reproduce the output from code in section "Example 10: Causal mediation model with continuous treatment", found on page 218 of manual "STATA CAUSAL INFERENCE AND TREATMENT EFFECTS ESTIMATION REFERENCE MANUAL. RELEASE 18". However, this returned the same error.

    I have not found any other posts on Statalist or other sites regarding this issue. I wanted to check if anyone else has had this issue, indicating that it might be an environment-specific issue, or if it is a bug? My primary suspicion is that this is due to the limitations of BE variable limits, but would appreciate some clarification/confirmation.

    Stata is up-to-date.
    Stata/BE 18 for Windows (64-bit x86-64)

    Full output from attempted reproduction of Stata example 10:

    Code:
    . use https://www.stata-press.com/data/r18/birthweight, clear
    (Fictional birthweight data)
    
    . 
    . summarize ses
    
        Variable |        Obs        Mean    Std. dev.       Min        Max
    -------------+---------------------------------------------------------
             ses |      2,000    7.804412    2.287496   1.304026   16.27844
    
    . generate std_ses = (ses-r(mean))/r(sd)
    
    . 
    . mediate (bweight sespar c.age##c.age, expmean) (ncigs sespar c.age##c.age, poisson) (std_ses, continuous(0 -2 -1 1 2)), nointeract
    
    Iteration 0:  EE criterion =  1.470e-12  
    Iteration 1:  EE criterion =  2.769e-17  
    
    Causal mediation analysis                                Number of obs = 2,000
    
    Outcome model:     Exponential mean
    Mediator model:    Poisson
    Mediator variable: ncigs
    Treatment type:    Continuous
    
    Continuous treatment levels:
      0: std_ses =  0 (control)
      1: std_ses = -2
      2: std_ses = -1
      3: std_ses =  1
      4: std_ses =  2
    
    ------------------------------------------------------------------------------
                 |               Robust
         bweight | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    NIE          |
         std_ses |
       (1 vs 0)  |  -276.2757   27.69004    -9.98   0.000    -330.5471   -222.0042
       (2 vs 0)  |  -100.1155   9.170566   -10.92   0.000    -118.0894   -82.14148
       (3 vs 0)  |   65.84585   5.423096    12.14   0.000     55.21678    76.47493
       (4 vs 0)  |   110.1346   8.724232    12.62   0.000     93.03538    127.2337
    -------------+----------------------------------------------------------------
    NDE          |
         std_ses |
       (1 vs 0)  |  -170.9012   31.33649    -5.45   0.000    -232.3196   -109.4828
       (2 vs 0)  |  -86.56069   16.08129    -5.38   0.000    -118.0794   -55.04193
       (3 vs 0)  |   88.83929   16.94031     5.24   0.000      55.6369    122.0417
       (4 vs 0)  |   180.0172   34.77372     5.18   0.000     111.8619    248.1724
    -------------+----------------------------------------------------------------
    TE           |
         std_ses |
       (1 vs 0)  |  -447.1769   35.41401   -12.63   0.000    -516.5871   -377.7667
       (2 vs 0)  |  -186.6761   15.73291   -11.87   0.000    -217.5121   -155.8402
       (3 vs 0)  |   154.6851   16.31969     9.48   0.000     122.6991    186.6712
       (4 vs 0)  |   290.1517   33.85571     8.57   0.000     223.7958    356.5077
    ------------------------------------------------------------------------------
    Note: Outcome equation does not include treatment–mediator interaction.
    
    . 
    . estat effectsplot
    variable __000003 not found
    r(111);
    
    end of do-file
    
    r(111);

  • #2
    Your code works fine in Stata 19. It sounds like a problem with a temporary variable not being found (double underscore and lots of zero's).

    Comment


    • #3
      I also have a pc with StataNow/SE 18.5, and your code worked there as well.

      Comment


      • #4
        I can confirm that I get the same error as OP. I am using StataNow/MP 19.5 on a Mac (macOS 15.5 on an M2 Pro chip).

        I set trace on with a tracedepth of 3. It seems that estat calls mediate_estat, which in turn calls _cma_estat_effectplot, which throws the error:

        Code:
              - tw `rcspc' `scspc' `addplot'
              = tw (rcap __00000M __00000N __000003, sort pstyle(p1)  ) (rcap __00000O __00000P __000003, sort pstyle(p2)  ) (rcap __00000Q __00000R __000003, so
        > rt pstyle(p3)  ) (connected __0000081 __000003, sort pstyle(p1) ) (connected __00000E1 __000003, sort pstyle(p2) ) (connected __00000K1 __000003, sort 
        > pstyle(p3) title(Effects plot) ytitle(Effect) xtitle(std_ses) legend(order(`" 4 "NIE" 5 "NDE" 6 "TE""') rows(3) pos(3))  ) 
        variable __000003 not found
        Last edited by Hemanshu Kumar; 19 Jul 2025, 18:21.

        Comment


        • #5
          This code runs without errors on my setup: StataNow v. 19.5 MP4, Windows 10, 64 bit, RAM 32GB.

          Comment


          • #6
            I think I may have partly figured out the issue here.

            I paused into the program _cma_estat_effectplot, and noticed that the temporary variable `atvar' created by svmat on line 36 of that ado file is actually __0000031 even though it is expected to be __000003. The trace below shows the expected name:
            Code:
                  - svmat `at', n(`atvar')
                  = svmat __000002, n(__000003)
            but here are the variables in memory:
            Code:
            -> . d
            
            Contains data from https://www.stata-press.com/data/r18/birthweight.dta
             Observations:         2,000                  Fictional birthweight data
                Variables:            10                  9 Jan 2023 21:28
            ---------------------------------------------------------------------------------------------------------------------------------------------------------
            Variable      Storage   Display    Value
                name         type    format    label      Variable label
            ---------------------------------------------------------------------------------------------------------------------------------------------------------
            id              int     %9.0g                 Subject identifier
            bweight         int     %9.0g                 Infant birthweight (grams)
            lbweight        byte    %9.0g      noyes      Low birthweight baby
            ncigs           byte    %9.0g                 Number of cigarettes smoked per day during pregnancy
            college         byte    %9.0g      noyes      College degree
            ses             float   %9.0g                 Socioeconomic status score (0–20)
            sespar          float   %9.0g                 Socioeconomic status score of parents (0–20)
            age             byte    %9.0g                 Age (years)
            std_ses         float   %9.0g                
            __0000031       float   %9.0g                
            ---------------------------------------------------------------------------------------------------------------------------------------------------------
            Sorted by:
                 Note: Dataset has changed since last saved.
            In turn, this causes a problem for me because by default I have set varabbrev off. If I set varabbrev on, the problem goes away. It would be useful if Clyde Schechter and/or Frode Andre can check if doing set varabbrev off on their systems makes the error pop up.

            I think it would be useful to raise this issue with Stata Technical Services. They may need to fix the code for svmat.ado.
            Last edited by Hemanshu Kumar; 19 Jul 2025, 20:49.

            Comment


            • #7
              Hemanshu Kumar Bingo! With -set varabbrev off-, I do, indeed, reproduce the error noted by O.P. and you. Certainly this is a matter for Stata Technical Services.

              Comment


              • #8
                Thanks for confirming, Clyde Schechter. I have just dropped a line to tech support.

                Comment


                • #9
                  That makes sense! I tried with set trace on but couldn't pinpoint the issue. Thanks all, I was driving myself stir crazy.

                  Special thanks to Hemanshu Kumar for contacting tech support as well.

                  Comment


                  • #10
                    Hi all, thanks for pointing this out, and apologies for the inconvenience. We will provide a fix for this in a future update.

                    Comment

                    Working...
                    X