Hi all
I have two problems which are tedious to solve if I need to manually type everything out, so I am looking for a smarter solution. I am posting them in the same post because they both fit under the same headliner.
In the first problem, my dataset is in the long format and I have a variable 'of' which needs to take the value one, if the variable 'y' takes on a different value than zero in the same row as 'of' and 49 rows below. This could be done typing out:
..continuing the code untill y[_n+49].
In the second problem, I need to drop observations if a long set of variables, lets call them a, b, c, takes on the value 0. Again this could be done writing
..continuing the code until I have listed every variable. I wonder if there would be some way of not having to write the "==0 &" part for every variable but just, e.g., defining a list of "a b c" and then writing to drop the observations if all variable in the list equals zero?
I have two problems which are tedious to solve if I need to manually type everything out, so I am looking for a smarter solution. I am posting them in the same post because they both fit under the same headliner.
In the first problem, my dataset is in the long format and I have a variable 'of' which needs to take the value one, if the variable 'y' takes on a different value than zero in the same row as 'of' and 49 rows below. This could be done typing out:
Code:
gen of = 0 replace of if y!=. & y[_n+1]!=. & y[_n+2]!=.
In the second problem, I need to drop observations if a long set of variables, lets call them a, b, c, takes on the value 0. Again this could be done writing
Code:
drop if a==0 & b==0 & c==0
Comment