Announcement

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

  • Code that picks up sudden spikes in prices

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double op
               35.58
               35.45
    32.7066666666667
               39.09
    37.2933333333333
               33.54
    31.7966666666667
    33.5233333333333
    30.6733333333333
    32.1066666666667
    31.8066666666667
               31.59
               29.16
               29.48
    30.2966666666667
               28.94
    29.2333333333333
    29.3133333333333
    28.1466666666667
               27.49
    27.3666666666667
               26.95
    27.0933333333333
    28.0733333333333
               17.16
    12.4433333333333
    12.4433333333333
               14.64
    17.7066666666667
               18.39
               18.94
    17.7566666666667
    15.7533333333333
               16.09
    14.0866666666667
    13.1466666666667
    17.0233333333333
               18.47
               17.41
               18.72
    19.4633333333333
               15.82
    25.6566666666667
                  31
               19.85
               18.33
    19.4233333333333
    19.8666666666667
    17.5066666666667
    19.6833333333333
    19.9966666666667
    18.9566666666667
               17.99
    17.9933333333333
                16.2
    14.9633333333333
               13.87
               16.27
               17.05
    16.6033333333333
    17.2233333333333
    18.1766666666667
               16.44
    16.9766666666667
    18.3133333333333
    19.4866666666667
               20.63
    23.0633333333333
    21.0833333333333
               18.49
    18.6566666666667
               18.84
    14.1633333333333
               13.28
    13.0033333333333
               11.85
    11.6433333333333
               16.03
    20.4433333333333
    23.8066666666667
    26.6166666666667
    26.7666666666667
    29.8833333333333
               29.67
               26.07
    26.7266666666667
    25.2133333333333
    19.3133333333333
    20.9233333333333
    25.2033333333333
    26.9366666666667
    26.7366666666667
    31.3366666666667
    26.4866666666667
    28.3833333333333
               29.36
               32.13
    35.6266666666667
    40.5533333333333
               42.73
    end
    This is the data I've gotten with regards to oil prices. However, as I want to illustrate the different oil price shocks over certain quarters for (eg. when oil prices were generally stable up until 1985Q4 to 1986Q1 when there was a drastic decrease). Do I have to manually go through the changes by looking at the line plot or looking at the values in the data browser or is there a way in which Stata illustrates these spikes? Thank you.

  • #2
    Well, you have to define what you mean by a spike. If you define a spike as a change in value from the preceding value by more than a certain absolute or relative amount, you can just code that directly.

    Comment

    Working...
    X