How to Find and Use Percentiles in Stata

127 Views Asked by At

I have a variable, income, that details some respondents' incomes. I now want to create a new variable, income_group, which has a value of 1 if the respondent's income is less than the 50th percentile, 2 if the respondent's income is between the 50th and 90th percentile, and 3 if it's greater than the 90th percentile. How would I go about doing this? Any help is appreciated. Thanks!

1

There are 1 best solutions below

5
TheIceBear On BEST ANSWER

Here is a reproducible example that shows how to do this:

clear
set obs 1000

* Generate a mock income var
generate income = runiform()

* Calculates the percentiles
summarize income, detail

* Show what values summarize stores for you
* (This line is not needed, just showing you)
return list

* Generate the categorical variable
generate income_group = 0
replace  income_group = 1 if income > r(p50)
replace  income_group = 2 if income > r(p75)
replace  income_group = 3 if income > r(p90)
replace  income_group = income if missing(income)