Announcement

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

  • command exp is unrecognized

    Dear all,

    My STATA cannot recognize the basic exp command. I got this:

    command exp is unrecognized
    r(199);

    This is the first time I use STATA 15 and I have no idea how to fix it.

    Many thanks

  • #2
    That's because there is no exp command in Stata.

    What is it you are trying to do?

    Comment


    • #3
      I was trying to get the exponential. I saw the command on one of introductory to STATA workshop.
      Attached Files

      Comment


      • #4
        As the page you show states, clearly, these are operators not commands. Every Stata statement, whether from a do-file, or in the Command window, must begin with a command. So if you have a variable x and you want to create a new variable y whose values are the exponentials of the values of x, it would be:

        Code:
        gen y = exp(x)
        -gen- is a command. You can't omit it.

        I think you need to step back from whatever you're doing and get acquainted with the basics of Stata. Go to the Help menu and select PDF Documentation. Within the documentation select the links to read the Getting Started [GS] volume, and the User's GUide [U] volume. It's a fair amount of reading, and you won't retain everything. But you will become familiar with the general syntax of Stata's language, the basic commands that are used all the time in Stata data management and analysis, and Stata's overall approach to data organization, manipulation, and analysis. When you complete that reading, you will find that in many situations you will be able to identify what command(s) are likely to play a role in your solution. Then you can consult the help files or the PDF documentation for the details you don't remember.

        Comment


        • #5
          exp is an operator, not a command. You can use operators inside of certain commands, for example:

          gen y = exp(x)

          If you want to see a simple calculation, you can type

          -disp exp(0.2)-

          Comment


          • #6
            Many thanks Clyde, that was very helpful.

            Comment


            • #7
              Strictly exp() is a function, not an operator... Functions take arguments, even if the argument is empty, as in runiform()

              A function can be recognised by its parentheses, just as the presence of claws narrows down the fauna you're looking at.

              Operators are always given by one or more symbols, with nary a parenthesis in sight.

              So whatever your source it's a little untrustworthy.

              Comment


              • #8
                @Clyde Schechter @Nick Cox
                Regarding the exp() function, I'm not sure I'm sure why I'm getting the r(133) error --it seems I'm using the exp operator wrong?
                I am trying to calculate the 95% CI for the Interaction Contrast Ratio using the nlcom command, following the tutorial by VanderWeel: https://www.degruyter.com/document/d...5/html?lang=en




                Attached Files
                Last edited by Brian Nguyen; 28 Dec 2022, 10:42.

                Comment


                • #9
                  You need to show the exact command you are using that produces this error message. Don't edit it in any way; there is no such thing as a "minor" change. Copy/paste it from your do-file, results window or log file directly into your post.

                  Comment


                  • #10
                    As already pointed out, exp() is a function, not an operator. The two terms are exclusives, not alternatives.

                    More importantly for your question, you're citing a long paper there and I am not clear where quotation stops and your code starts.

                    Please back up and show a self-contained reproducible example based on data you show or a standard Stata dataset.

                    Comment


                    • #11
                      Clyde Schechter

                      Attached Files

                      Comment


                      • #12
                        The problem is that you copy/pasted the code from that website and then just edited the variable names to match your needs. When you take code from websites, or Word documents, or other pretty-print formats, you can get burned by characters that look like they are correct to our eyes, but are in fact not what they appear to be. In this particular case, the culprit is that what you think are minus signs in your -nlcom- command are actually en-dahses. When the parser hits those, it doesn't know what they are, gets confused, and gives you a misleading error message. Proof of this:
                        Code:
                        . clear*
                        
                        . webuse nhanes2
                        
                        .
                        . svyset
                        
                        Sampling weights: finalwgt
                                     VCE: linearized
                             Single unit: missing
                                Strata 1: strata
                         Sampling unit 1: psu
                                   FPC 1: <zero>
                        
                        .
                        . gen bxf = black*female
                        
                        .
                        . rename bxf Ige
                        
                        . rename black g
                        
                        . rename female e
                        
                        .
                        . svy, subpop (if age < 30): logistic diabetes hlthstat heartatk age e g Ige
                        (running logistic on estimation sample)
                        
                        note: heartatk != 0 predicts failure perfectly;
                              heartatk omitted and 1 obs not used.
                        
                        Survey: Logistic regression
                        
                        Number of strata = 31                            Number of obs   =      10,350
                        Number of PSUs   = 62                            Population size = 117,145,061
                                                                         Subpop. no. obs =       2,319
                                                                         Subpop. size    =  32,845,245
                                                                         Design df       =          31
                                                                         F(5, 27)        =        9.25
                                                                         Prob > F        =      0.0000
                        
                        ------------------------------------------------------------------------------
                                     |             Linearized
                            diabetes | Odds ratio   std. err.      t    P>|t|     [95% conf. interval]
                        -------------+----------------------------------------------------------------
                            hlthstat |   2.166251   .8569581     1.95   0.060     .9667424    4.854079
                            heartatk |          1  (omitted)
                                 age |   1.185787   .0748278     2.70   0.011     1.042588    1.348656
                                   e |   5.537152   4.622936     2.05   0.049     1.008741    30.39439
                                   g |   5.829577   5.414582     1.90   0.067      .876884    38.75537
                                 Ige |    .310532   .3905926    -0.93   0.360     .0238779    4.038476
                               _cons |   4.09e-06   6.20e-06    -8.19   0.000     1.87e-07    .0000898
                        ------------------------------------------------------------------------------
                        Note: _cons estimates baseline odds.
                        
                        .
                        . // TYPED BY HAND
                        . nlcom exp(_b[g]+_b[g]+_b[Ige])-exp(_b[g])-exp(_b[e])+1
                        
                               _nl_1: exp(_b[g]+_b[g]+_b[Ige])-exp(_b[g])-exp(_b[e])+1
                        
                        ------------------------------------------------------------------------------
                            diabetes | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
                        -------------+----------------------------------------------------------------
                               _nl_1 |   .1863798   9.980741     0.02   0.985    -19.37551    19.74827
                        ------------------------------------------------------------------------------
                        
                        .
                        . // COPY PASTED FROM https://www.degruyter.com/document/doi/10.1515/em-2013-0005/html?lang=en
                        . // WITH - CHARACTERS HAND EDITED IN
                        . 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
                        
                        ------------------------------------------------------------------------------
                            diabetes | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
                        -------------+----------------------------------------------------------------
                               _nl_1 |  -.3429876   8.810202    -0.04   0.969    -17.61067    16.92469
                        ------------------------------------------------------------------------------
                        
                        .
                        . // COPY PASTED FROM https://www.degruyter.com/document/doi/10.1515/em-2013-0005/html?lang=en
                        . nlcom exp(_b[g]+_b[e]+_b[Ige])–exp(_b[g])–exp(_b[e])+1
                        
                        unknown function ()
                        r(133);
                        
                        end of do-file
                        
                        r(133);
                        The solution is to just retype the command by hand, and you will be OK. (Or, in this case, you just have to retype the two minus signs by hand.)
                        Last edited by Clyde Schechter; 28 Dec 2022, 13:05.

                        Comment


                        • #13
                          Clyde Schechter Dear Clyde, you are 100% correct. It works now, I feel silly. Thank you for helping me with this!

                          Comment


                          • #14
                            I feel silly
                            Why would you feel silly about that? You can stare at that line of code in your do-file editor all day and there is absolutely nothing you can see that will point you in the direction of the problem. The first time I got tripped up by this kind of problem, I had no clue what could be causing it. I found the answer on Statalist. Of course, since then, whenever I get funky results from code that was pasted from somewhere (even from the Stata PDF documentation!) it's the first thing I think of. But I don't think it would have ever occurred to me otherwise.

                            As an old math professor once said to me, everything is obvious once you've seen it.

                            Comment

                            Working...
                            X