Hi,

I have the following data. I am trying to compute the mean for each occupation category in the "occupation_category" variable. I want loop to skip if occupation_category == "Others" and if occupation_category == "Farm Sector".


* Example generated by -dataex-. To install: ssc install dataex
clear
input str21 occupation_category long total_income
"Blue Collar" 15500
"White Collar" 32000
"Others" 8000
"Selfemployed_informal" 36000
"Farm Sector" 15500
"Selfemployed_formal" 15500
"Retired_Aged" 6000
"Blue Collar" 28000
"White Collar" 20000
"Others" 23000
"Selfemployed_informal" 12000
"Farm Sector" 6000
"Selfemployed_formal" 33000
"Retired_Aged" 9250
"Blue Collar" 30000
"White Collar" 15000
"Others" 9500
"Selfemployed_informal" 10250
"Farm Sector" 35000
"Selfemployed_formal" 14000
"Retired_Aged" 30000
"Blue Collar" 6050
"White Collar" 11000
"Others" 25000
"Selfemployed_informal" 35000
"Farm Sector" 16500
"Selfemployed_formal" 30000
"Retired_Aged" 27000
"Blue Collar" 10000
"White Collar" 15000
"Others" 32000
"Selfemployed_informal" 10000
"Farm Sector" 32000
"Selfemployed_formal" 9750
"Retired_Aged" 32250
"Blue Collar" 25000
"White Collar" 32000
"Others" 17250
"Selfemployed_informal" 12250
"Farm Sector" 35000
"Selfemployed_formal" 6250
"Retired_Aged" 13000
"Blue Collar" 17500
"White Collar" 14000
"Others" 43000
"Selfemployed_informal" 10000
"Farm Sector" 15500
"Selfemployed_formal" 13250
"Retired_Aged" 9250
"Blue Collar" 10000
"White Collar" 20000
"Others" 27750
"Selfemployed_informal" 16500
"Farm Sector" 35000
"Selfemployed_formal" 9000
"Retired_Aged" 30000
end
[/CODE]

I ran the following code. However, it is running acctoss all occupation categories.

Code:

levelsof occupation_category, local(occupation)
foreach i of local occupation {

di "Occupation Category = `i'"

if occupation_category == "Others" & if occupation_category == "Farm Sector"{

}
  tabstat total_income if occupation_category == "`i'" , stat(mean semean) format(%9.0g)

}

Please help.