Here is an example of data:
name_id | year | value_share | dummy variable I want |
city1 | 1 | 0.127 | 1 |
city1 | 2 | 0 | 1 |
city2 | 1 | 0.0530 | 0 |
city2 | 2 | 0.275 | 0 |
city3 | 1 | 0 | 0 |
city3 | 2 | 0.235 | 0 |
city4 | 1 | 0.874 | 1 |
city4 | 2 | 0.573 | 1 |
This seems rather rudimentary but I can't seem to think of any way of doing this using only one command (one line) ideally. Also, I don't wish to drop any IDs from the data (like dropping those who don't meet criteria) nor creating a subset nor combining years 1 and 2 into a single row per city.
Out of interest, how would the command differ if one needed to generate a dummy variable attributed to all observations of an ID provided at least one observation (non-specific) out of the ID's observations' meets a certain a certain criteria?
0 Response to Generate dummy variable attributed to all observations of an ID if one of the observations meets criteria
Post a Comment