I work with Stata I need to assign people to income quintiles in each county. So I have a data containing two variables: household total income and a variable "county" which indicate the county of residence (each county corresponds to a certain number like 1, 2, 3, etc.). I use xtile command, like
xtile quart=tot_income if county==2, nq(10)
so I create a variable "quart" which indicates in which quintile is the household which resides in "county" numbered 2. Now, the problem is that I have some 1000 counties and I do not want to do it by hand for each one. I though there must be a way to this operation for each county in one command in a loop. I tried "foreach" loop command, but I did not manage to do it. specifically I did:
1. foreach i in county {
2. xtile quart=tot_income if county == `i', nq(10)
3. }
But no, it did not work, it does the xtile command but for entire sample. Can anybody suggest me what to do?
xtile quart=tot_income if county==2, nq(10)
so I create a variable "quart" which indicates in which quintile is the household which resides in "county" numbered 2. Now, the problem is that I have some 1000 counties and I do not want to do it by hand for each one. I though there must be a way to this operation for each county in one command in a loop. I tried "foreach" loop command, but I did not manage to do it. specifically I did:
1. foreach i in county {
2. xtile quart=tot_income if county == `i', nq(10)
3. }
But no, it did not work, it does the xtile command but for entire sample. Can anybody suggest me what to do?
Comment