0

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")
  • Can you provide a sample of your dataset? You can read more about that here: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Matt Jul 15 '20 at 13:05

1 Answers1

2

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.

Thomas Lumley
  • 1,893
  • 5
  • 8