Announcement

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

  • Additive interaction--error message when using nlcom

    Dear Stata experts:

    I'm attempting to assess additive interaction between age and another exposure in a dataset from a large-scale cohort study. The code I have written is based on sample Stata code given in this article by VanderWeele and Knol (2014): A Tutorial on Interaction (degruyter.com)

    Following the example given in the article, I first created a term for interaction between age and another exposure, then ran a logistic regression model.
    Code:
     gen agexother=age*other
    Code:
    logit outcome age other agexother cov1 cov2 . . . covN
    I then entered the code, based upon the sample code of VanderWeele and Knol:
    Code:
    nlcom exp(_b[age]+_b[other]+_b[agexother])–exp(_b[ag0])–exp(_b[other])+1
    Stata returns:
    unknown function ()
    r(133);

    My collaborators and I have been unable to determine why Stata is returning this error message, although we wonder if it may be due to a change in the Stata command structure between the time the attached article was published and the current version of Stata. Can anyone advise me?

  • #2
    CE Wright:
    welcome to this forum.
    What strikes me is:
    Code:
     
     –exp(_b[ag0])
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thank you for the welcome and for your rapid response, Carlos. That was an error on my part when copying and pasting code into the forum--my apologies. In the actual Stata code, I entered age correctly, so that would not have triggered the error message I'm getting.

      Comment


      • #4
        I was able to reproduce your problem.
        Code:
        . sysuse auto, clear
        (1978 automobile data)
        
        . rename (price length) (g e)
        
        . generate Ige = g*e
        
        . logit foreign g e Ige displacement
        
        Iteration 0:   log likelihood =  -45.03321  
        Iteration 1:   log likelihood = -20.879526  
        Iteration 2:   log likelihood = -14.292488  
        Iteration 3:   log likelihood =  -12.96057  
        Iteration 4:   log likelihood = -12.856392  
        Iteration 5:   log likelihood = -12.851209  
        Iteration 6:   log likelihood = -12.851186  
        Iteration 7:   log likelihood = -12.851186  
        
        Logistic regression                                     Number of obs =     74
                                                                LR chi2(4)    =  64.36
                                                                Prob > chi2   = 0.0000
        Log likelihood = -12.851186                             Pseudo R2     = 0.7146
        
        ------------------------------------------------------------------------------
             foreign | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                   g |   .0063617   .0060044     1.06   0.289    -.0054067    .0181302
                   e |   .0851449   .1436347     0.59   0.553    -.1963738    .3666637
                 Ige |  -.0000275   .0000324    -0.85   0.396    -.0000909     .000036
        displacement |  -.0583858   .0365718    -1.60   0.110    -.1300653    .0132937
               _cons |  -15.72015   25.92725    -0.61   0.544    -66.53663    35.09633
        ------------------------------------------------------------------------------
        Note: 3 failures and 0 successes completely determined.
        
        . nlcom exp(_b[g]+_b[e]+_b[Ige])–exp(_b[g])–exp(_b[e])+1
        
        unknown function ()
        r(133);
        To do so I copied the nlcom command from the online copy of the article and pasted it into the do-file editor window, and then renamed my variables to match the code. I'm guessing you did something similar but edited the pasted code to contain your variable names.

        To solve the problem I reran my code having commented out the pasted nlcom command and then retyped it - no copying and pasting.
        Code:
        . // nlcom exp(_b[g]+_b[e]+_b[Ige])–exp(_b[g])–exp(_b[e])+1
        . 
        . nlcom exp(_b[g]+_b[e]+_b[Ige])-exp(_b[g])-exp(_b[e])+1
        
               _nl_1: exp(_b[g]+_b[e]+_b[Ige])-exp(_b[g])-exp(_b[e])+1
        
        ------------------------------------------------------------------------------
             foreign | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
               _nl_1 |   .0005371   .0014463     0.37   0.710    -.0022975    .0033717
        ------------------------------------------------------------------------------
        
        .
        We see problems with pasted code occasionally on Statalist with code that has been copied from sources other than plain text.

        Comment


        • #5
          I'll be darned. That solved the problem! Thank you so, so much, William!

          Comment

          Working...
          X