Hello,
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
this is my data
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
I have tried this code and genarates 1s for the above values
Code:
forvalues i=171/250{
bysort town_id: generate ID_`i' =1
replace ID_`i'=0 if ID<_n
}
Kindly assist