Hello Statalist,
I have a panel data of stock prices with open high low and close and it looks something like this:
I would like to create a dummy variable that take the value of 1 if it meets at least one of the following four conditions :
1. (((TradeOpen [_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0.15)
2. (((TradeHigh [_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0.15)
3. (((TradeLow [_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0.15)
4. (((TradeClose [_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0.15)
I have tried different codes but I got contradicting results. For instance:
I do not think that " by id" is necessary in the first line but I just threw it there anyways but might be important for the second line, correct me if I am mistaken. Another code that I have tried is the following:
Again, I am not sure if each "replace" line overrides the previous one or they all work together.
Any help in this regard is highly appreciated.
Saad
I have a panel data of stock prices with open high low and close and it looks something like this:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double(TradeOpen TradeHigh TradeLow TradeClose) 26.500053 27.000054000000002 26.500053 26.66672 26.833387000000002 26.833387000000002 26.500053 26.833387000000002 26.66672 26.833387000000002 26.416719500000003 26.7500535 end
I would like to create a dummy variable that take the value of 1 if it meets at least one of the following four conditions :
1. (((TradeOpen [_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0.15)
2. (((TradeHigh [_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0.15)
3. (((TradeLow [_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0.15)
4. (((TradeClose [_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0.15)
I have tried different codes but I got contradicting results. For instance:
Code:
by id: gen dummy1= 0 by id: replace dummy1= 1 if (((TradeOpen [_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0.15) | (((TradeHig > h [_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0.15) | (((TradeLow [_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0. > 15) | (((TradeClose [_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0.15)
Code:
by id: gen dummy1= 0 replace if dummy1= ((TradeOpen [_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0.15 replace if dummy1= ((TradeHigh [_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0.15 replace if dummy1= ((TradeLow[_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0.15 replace if dummy1= ((TradeClose[_n] - TradeClose[_n-1]) / TradeClose[_n-1]) >= 0.15
Any help in this regard is highly appreciated.
Saad
Comment