Md Shariful Islam
Md Shariful Islam

Reputation: 71

Getting proportion of two or more variables with one code

I am analysing a complex survey data. I want to calculate the proportion of smoking among rural men and urban men and alcohol consumption. I used separate code like below. Is it possible to get the same result using one code for urban_rural and alcohol?

svyciprop(~smoking, subset(svs1, urban_rural =='rural'), method = "likelihood")
svyciprop(~smoking, subset(svs1, urban_rural =='urban'), method = "likelihood")
svyciprop(~smoking, subset(svs1, alcohol =='yes'), method = "likelihood")
svyciprop(~smoking, subset(svs1, alcohol =='no'), method = "likelihood")

Upvotes: 0

Views: 446

Answers (1)

Thomas Lumley
Thomas Lumley

Reputation: 2765

Up to a point, yes, you can use svyby to get the answers for each category of a variable

svyby(~smoking, ~urban_rural, design=svs1, svyciprop, method="likelihood", vartype="ci")
svyby(~smoking, ~alcohol, design=svs1, svyciprop, method="likelihood", vartype="ci")

There isn't any way to do this for a list of variables without some sort of explicit loop or mapping function.

Upvotes: 2

Related Questions