Prajwal Mani Pradhan
Prajwal Mani Pradhan

Reputation: 397

Between equivalent in Stata

I want to flag all rows that have salaries between 100,000 and 500,000. I have Data1.dta as:

ID  Salary
1   100000
2   65000
3   400000
4   5000000

Is there a way to create a flag variable in Stata using SQL's between operator or its equivalent?

The resulting dataset would look like this:

ID  Salary     six_figures
1   100000     1
2   65000      0
3   400000     1
4   5000000    0

I can only think of following

gen six_figures = 0
replace six_figures = 1 if salary == 100000
replace six_figures = 1 if salary == 100001

... and so on. Which would be inefficient and silly.

Upvotes: 0

Views: 62

Answers (1)

Bicep
Bicep

Reputation: 1103

gen six_figures = 0
replace six_figures = 1 if inrange(salary,100000,500000)

or

gen six_figures = 0
replace six_figures = 1 if salary >= 100000 & salary <= 500000

Upvotes: 1

Related Questions