Announcement

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

  • How to use e in stata?

    Hello every one.

    How can i run this equation in stata?


    1/(1+e-x)


    I can calculate x separately, but how to use the function e-x i am not very sure.

    Thanks in advance.


  • #2
    Do not know what you mean by "run this equation", the function is -exp()-
    Code:
    . dis exp(-7)
    .00091188

    Comment


    • #3
      Originally posted by Joro Kolev View Post
      Do not know what you mean by "run this equation", the function is -exp()-
      Code:
      . dis exp(-7)
      .00091188
      i need to generate a variable equal: 1/(1+e-x), and I already calculated x.

      SO should I just write the code:

      gen wanted= 1/(1+exp(-x))

      Thanks

      Comment


      • #4
        You might want invlogit(); you probably do not want the result in a variable ...

        Comment


        • #5
          Originally posted by daniel klein View Post
          You might want invlogit(); you probably do not want the result in a variable ...
          Hi Daniel, could you explain why should I not use the result in a variable?


          I need to generate a variable Z, where Z=1/(1+e-x),

          and X was also generate by a equation: X=a+b+c+d+e.

          In this situation, how should I run this?

          Thank you so very much.

          Comment


          • #6
            You gave very little information before. If X is a variable, you probably want Z to be a variable, too. What I was implying is that you do not want to store a constant in a variable; there are exceptions for this, too.

            Comment


            • #7
              Yes Lucas, just write -gen wanted= 1/(1+exp(-x))-.

              Or use -invlogit- like Daniel suggested.

              Code:
              . sysuse auto, clear
              (1978 Automobile Data)
              
              . gen wanted= 1/(1+exp(-rep))
              (5 missing values generated)
              
              . gen wanted2 = invlogit(rep)
              (5 missing values generated)
              
              . summ wanted*
              
                  Variable |        Obs        Mean    Std. Dev.       Min        Max
              -------------+---------------------------------------------------------
                    wanted |         69     .952005    .0504659   .7310586   .9933072
                   wanted2 |         69     .952005    .0504659   .7310586   .9933072

              Comment


              • #8
                invlogit(x) = exp(x)/{1 + exp(x)} = exp(x)/{exp(x)*(1/exp(x) + 1)} = 1/{exp(-x) + 1}

                Comment


                • #9
                  Originally posted by Joro Kolev View Post
                  invlogit(x) = exp(x)/{1 + exp(x)} = exp(x)/{exp(x)*(1/exp(x) + 1)} = 1/{exp(-x) + 1}
                  Thanks Joro! You are very helpful.

                  Comment

                  Working...
                  X