I am trying to use for loops to build up the code for the collapse command. I want to end up with globals with elements of the form "p90age = age"
My hope was that I would end up with 9 globals each containing the necessary code for a collapse command of the form:
But, instead each global ends up with only the last element in it. E.g. pc99 =" P_movedin99 = moved". What is strange is that I can add elements manually with essentially the same syntax. I'd be very grateful for any advice.
Thanks,
Stu
Code:
global details "age occ ind wkswork1 inc poverty occscore movedin " global ptiles "1 5 10 25 50 75 90 95 99" foreach p of global ptiles { global pc`p' "" foreach v of global details { global pc`p' " $pc`p' P_`v'`p'= `v' " } }
Code:
collapse p(10) $pc10 p(25) $pc25 , by(year)
Thanks,
Stu
Comment