# Collapsing variables

#### Andrej.C.

##### New Member
Hey there,

I am new to STATA and would like to solve the following problem:
Lets say that I have variable "consumption of cereals" and variable "net income". I would like to find out how much of cereals is consumed in average by the poorest 10% and the richest 10% of the population in my dataset. Any command which I could use? I will appreciate your suggestions. Thank you

Best regards,

Andrej

#### RedOwl

##### New Member
You don't need to use the collapse command.

Just use syntax similar to the following with _pctile.

Code:
sysuse auto, clear
tab weight

_pctile weight, nq(100)
gen lowpct = weight <= r(r10)
tab weight if lowpct

_pctile weight, nq(100)
gen hipct = weight >= r(r90)
tab weight if hipct
If you don't understand what r(r10) and r(r90) are, see the following:

Code:
_pctile weight, nq(100)
return list
For more help on working with percentiles see,

Code:
help pctile
You could also get deciles using the following:

Code:
summarize weight, detail
return list
For help, see:

Code:
help summarize

Last edited:

#### bukharin

##### RoboStataRaptor
You may also want to look at the -centile- command, eg:
Code:
centile weight, centile(10 90)