I have a data with repeated numeric observations and would like to generate dummies that end with the value of that number and assign 1 to all values of that repeated observation.
For example
ID | ID_171 | ID_180 |
171 | 1 | 0 |
171 | 1 | 0 |
171 | 1 | 0 |
180 | 0 | 1 |
180 | 0 | 1 |
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int town_id 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 171 180 180 180 180 180 180 191 191 191 191 191 191 end
Code:
forvalues i=171/250{ bysort town_id: generate ID_`i' =1 replace ID_`i'=0 if ID<_n }
0 Response to Generate dummy from repeated values
Post a Comment