Announcement

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

  • Percentage change variable for daily data

    Hello,

    I am writing my dissertation thesis on the impact of Brexit negotiations on the value of the pound in 2019. To do this, I am empirically testing the change in several exchange rates as a result of news developments concerning Brexit.

    I want to create a variable that measures the percentage change between the close price of each day.

    My data is set up as follows:

    close
    1st day - 1.275429
    2nd - 1.252191
    3rd - 1.262881
    4th - 1.273496
    5th - 1.278609

    I want to create a variable that performs the rate of returns formula, which in this instance would be: close - close-1 / close (e.g. with a above data: 1.252191 - 1.275429 / 1.252191)

    Any advice on how to create this variable would be much appreciated.


  • #2
    It appears that you want to calculate the percentage change. I was always taught that this is

    $$\frac{\text{New value - Old value}}{\text{Old value}}\times 100$$

    so check your formula. You can do it directly after tssetting your time series or approximate this with differences in logs.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(day close)
    1 1.275429
    2 1.252191
    3 1.262881
    4 1.273496
    5 1.278609
    end
    
    tsset day
    gen wanted= (close-l.close)/l.close
    gen lnclose= ln(close)
    gen wanted2= lnclose-l.lnclose
    Res.:

    Code:
    . l
    
         +---------------------------------------------------+
         | day      close      wanted    lnclose     wanted2 |
         |---------------------------------------------------|
      1. |   1   1.275429           .   .2432826           . |
      2. |   2   1.252191   -.0182198   .2248948   -.0183878 |
      3. |   3   1.262881    .0085371   .2333957    .0085009 |
      4. |   4   1.273496    .0084054   .2417659    .0083703 |
      5. |   5   1.278609    .0040149   .2457728    .0040069 |
         +---------------------------------------------------+

    Comment


    • #3
      A crucial detail in Andrew Musau's helpful post is using parentheses precisely as and where needed.

      Comment


      • #4
        l have tried performing this command, but the variable created contains only empty cells.

        Any idea on why this is?

        Thanks

        Comment


        • #5
          You need to provide more information. Show all your commands and the resulting Stata output.

          Comment

          Working...
          X