Announcement

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

  • Command for division with ln


    Hello guys! I would like help to use a command in stata for the following formula that I use in excel ln (x_ current / x_ previous)? Can someone help me please?

  • #2
    Code:
    generate ratio = ln(x_current/x_previous)

    Comment


    • #3

      William, thank you, but I think I wrote the question in a confused way, sorry. The formula didn't work. Example: 11/8/2020 - 2.45 (current) 11/9/2020 - 3.08 (previous) In excel excel I use: ln (2.45 / 3.08) In the stata I should use which command?

      Comment


      • #4
        This doesn't look like a different question. In Stata you can work calculator style as in


        Code:
        . display 2 + 2
        4
        
        . di 2 + 2
        4
        
        . di ln(2.45 / 3.08)
        -.22884157
        but it seems more likely that you should want to work on entire variables. William Lisowski guessed at your variable names from what you wrote in #1.


        Comment


        • #5
          Perhaps this is what you meant.
          Code:
          . list
          
               +----+
               |  x |
               |----|
            1. |  1 |
            2. |  2 |
            3. |  4 |
            4. | 12 |
               +----+
          
          . generate ratio = ln(x/x[_n-1])
          (1 missing value generated)
          
          . list
          
               +---------------+
               |  x      ratio |
               |---------------|
            1. |  1          . |
            2. |  2   .6931472 |
            3. |  4   .6931472 |
            4. | 12   1.098612 |
               +---------------+
          As should be apparent from these posts, your question really isn't clear without more detail, or at a minimum it is too difficult to guess at a good answer from what you have shared. Please help us help you. Show example data. For the example data, use a calculator to compute the results you want and tell us what they are. The Statalist FAQ provides advice on effectively posing your questions, posting data, and sharing Stata output..

          Comment


          • #6
            Originally posted by William Lisowski View Post
            Perhaps this is what you meant.
            Code:
            . list
            
            +----+
            | x |
            |----|
            1. | 1 |
            2. | 2 |
            3. | 4 |
            4. | 12 |
            +----+
            
            . generate ratio = ln(x/x[_n-1])
            (1 missing value generated)
            
            . list
            
            +---------------+
            | x ratio |
            |---------------|
            1. | 1 . |
            2. | 2 .6931472 |
            3. | 4 .6931472 |
            4. | 12 1.098612 |
            +---------------+
            As should be apparent from these posts, your question really isn't clear without more detail, or at a minimum it is too difficult to guess at a good answer from what you have shared. Please help us help you. Show example data. For the example data, use a calculator to compute the results you want and tell us what they are. The Statalist FAQ provides advice on effectively posing your questions, posting data, and sharing Stata output..
            This formula worked. Thank you, Thank you! I apologize. I started using the stata recently and I have difficulty, even to elaborate the questions I am confused. I need to find the stock return, in the period of 2010-2019, there are 370 companies. I must control the sector and the year.

            Comment


            • #7
              Originally posted by Nick Cox View Post
              This doesn't look like a different question. In Stata you can work calculator style as in


              Code:
              . display 2 + 2
              4
              
              . di 2 + 2
              4
              
              . di ln(2.45 / 3.08)
              -.22884157
              but it seems more likely that you should want to work on entire variables. William Lisowski guessed at your variable names from what you wrote in #1.

              Thank you!!

              Comment

              Working...
              X