Hello,
I’m struggling with generating a variable conditional on the outcome of another variable.
I created a dummy variable which gets value of 1 when day of a month is 1 to 15 and 0 otherwise. I would like a new variable to get lagged value of umich (already created) if day of a month is between 1 and 15 (dummy == 1) and current value of umich when day of month is greater than 15 (dummy == 0).
I experimented with egen and xi, but can’t figure it out by myself.
Thank you for your time!
Frank
I’m struggling with generating a variable conditional on the outcome of another variable.
I created a dummy variable which gets value of 1 when day of a month is 1 to 15 and 0 otherwise. I would like a new variable to get lagged value of umich (already created) if day of a month is between 1 and 15 (dummy == 1) and current value of umich when day of month is greater than 15 (dummy == 0).
I experimented with egen and xi, but can’t figure it out by myself.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str8 ticker double(date umich) float(lag_umich day first_half) "AAPL" 13165 105.8 102.4 17 0 "AAPL" 13257 107.8 105.4 18 0 "AAPL" 13348 107.5 105.4 18 0 "AAPL" 13439 106.6 102 17 0 "AAPL" 13530 106.8 104.9 16 0 "AAPL" 13621 115.2 109.8 17 0 "AAPL" 13712 114 113.2 17 0 "AAPL" 13803 109.8 114.1 16 0 "AAPL" 13894 113.5 111.4 15 1 "AAPL" 13985 115.5 113.7 16 0 "AAPL" 14076 113.3 115.4 16 0 "AAPL" 14166 112.8 111.7 14 1 end format %td date
Frank
Comment