Dear Statalists,
I would like to calculate the for each day maximum Price based on the previous 3 month data. I am using the command rangestat (max) max_price = prc, interval(date -90 0) .
I am facing two issues:
1.not always there are 90 days during the month, can be more can be less. I thought, extracting months from date variable and changing the code like this: rangestat (max) max_price = prc, interval(date -2 0) would help but it did not.
2. Stata is giving the max values even when there is not sufficient past data.
This is how my data looks like:
----------------------- copy starting from the next line -----------------------
I would like to calculate the for each day maximum Price based on the previous 3 month data. I am using the command rangestat (max) max_price = prc, interval(date -90 0) .
I am facing two issues:
1.not always there are 90 days during the month, can be more can be less. I thought, extracting months from date variable and changing the code like this: rangestat (max) max_price = prc, interval(date -2 0) would help but it did not.
2. Stata is giving the max values even when there is not sufficient past data.
This is how my data looks like:
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double permno long date str8 cusip double prc 10001 15006 "36720410" 9.875 10001 15007 "36720410" 9.5 10001 15008 "36720410" 9.96875 10001 15011 "36720410" 9.96875 10001 15012 "36720410" -9.734375 10001 15013 "36720410" -9.71875 10001 15014 "36720410" -9.71875 10001 15015 "36720410" 9.5 10001 15018 "36720410" 9.875 10001 15019 "36720410" 9.5 10001 15020 "36720410" 9.5 10001 15021 "36720410" 9.375 10001 15022 "36720410" 9.375 10001 15026 "36720410" 9.375 10001 15027 "36720410" 9.5 10001 15028 "36720410" 9.375 10001 15029 "36720410" 9.625 10001 15032 "36720410" 9.8125 10001 15033 "36720410" 9.8125 10001 15034 "36720410" 9.75 10001 15035 "36720410" 9.75 10001 15036 "36720410" -9.625 10001 15039 "36720410" 9.5 10001 15040 "36720410" 9.75 10001 15041 "36720410" 9.5 10001 15042 "36720410" 9.5 10001 15043 "36720410" 9.75 10001 15046 "36720410" 9.5 10001 15047 "36720410" 9.8125 10001 15048 "36720410" 9.75 10001 15049 "36720410" 9.625 10001 15050 "36720410" -9.625 10001 15053 "36720410" 9.8125 10001 15054 "36720410" 9.8125 10001 15055 "36720410" 9.8125 10001 15056 "36720410" 9.875 10001 15057 "36720410" 10 10001 15060 "36720410" 10 10001 15061 "36720410" 10.3125 10001 15062 "36720410" 10.1875 10001 15063 "36720410" 10.25 10001 15064 "36720410" 10 10001 15067 "36720410" 10 10001 15068 "36720410" 10.25 10001 15069 "36720410" 10 10001 15070 "36720410" 10.3125 10001 15071 "36720410" 10.1875 10001 15074 "36720410" 10.149999618530273 10001 15075 "36720410" 9.899999618530273 10001 15076 "36720410" 9.899999618530273 10001 15077 "36720410" 9.899999618530273 10001 15081 "36720410" 9.899999618530273 10001 15082 "36720410" -9.824999809265137 10001 15083 "36720410" -9.800000190734863 10001 15084 "36720410" 10.199999809265137 10001 15085 "36720410" 9.75 10001 15088 "36720410" 10.100000381469727 10001 15089 "36720410" 10.100000381469727 10001 15090 "36720410" 9.899999618530273 10001 15091 "36720410" 10.100000381469727 10001 15092 "36720410" 9.699999809265137 10001 15095 "36720410" 9.75 10001 15096 "36720410" 9.850000381469727 10001 15097 "36720410" 9.850000381469727 10001 15098 "36720410" 10 10001 15099 "36720410" 9.720000267028809 10001 15102 "36720410" 9.800000190734863 10001 15103 "36720410" 9.699999809265137 10001 15104 "36720410" 9.949999809265137 10001 15105 "36720410" 9.75 10001 15106 "36720410" 9.949999809265137 10001 15109 "36720410" 9.949999809265137 10001 15110 "36720410" 9.979999542236328 10001 15111 "36720410" 9.989999771118164 10001 15112 "36720410" 10.5 10001 15113 "36720410" 10.489999771118164 10001 15116 "36720410" 10.489999771118164 10001 15117 "36720410" 10.420000076293945 10001 15118 "36720410" 10.5 10001 15119 "36720410" 11.25 10001 15120 "36720410" 11 10001 15124 "36720410" 10.5 10001 15125 "36720410" 10.75 10001 15126 "36720410" 10.699999809265137 10001 15127 "36720410" 10.75 10001 15130 "36720410" 10.649999618530273 10001 15131 "36720410" 11.5 10001 15132 "36720410" -10.795000076293945 10001 15133 "36720410" 10.5 10001 15134 "36720410" 11.25 10001 15137 "36720410" 11 10001 15138 "36720410" 11.25 10001 15139 "36720410" 11.5 10001 15140 "36720410" 11 10001 15141 "36720410" 11 10001 15144 "36720410" 11.25 10001 15145 "36720410" 11.5 10001 15146 "36720410" 11.5 10001 15147 "36720410" 13 10001 15148 "36720410" 12.5 end format %d date
Comment