Reputation: 23
I'm trying to use svytotal to calculate the population breakdown of each pair (PUMA, BDSP). When I use svyby, it works as I would expect:
> svyby(~NP, ~factor(PUMA)+factor(BDSP), ss12hsf, svymean)
factor(PUMA) factor(BDSP) NP se
7501.0 7501 0 0.8328120 0.10738595
7502.0 7502 0 1.1790473 0.10128726
7503.0 7503 0 1.0707710 0.05241559
7504.0 7504 0 0.9982076 0.16726445
...
However, when I try to do the same with svytotal, it seems to just do a list concatenation instead of a cross product:
> svytotal(~factor(PUMA)+factor(BDSP), ss12hsf)
total SE
factor(PUMA)7501 66732 514704
factor(PUMA)7502 66350 570194
factor(PUMA)7503 71129 1597630
factor(PUMA)7504 54108 595059
factor(PUMA)7505 44327 498771
factor(PUMA)7506 40461 424705
factor(PUMA)7507 33792 216696
factor(BDSP)0 50036 867466
factor(BDSP)1 111847 1049884
factor(BDSP)2 111976 1586937
factor(BDSP)3 69279 1112640
factor(BDSP)4 24386 496505
factor(BDSP)5 5841 384093
factor(BDSP)10 3534 88227
Any ideas or suggestions?
Upvotes: 2
Views: 2186
Reputation: 6114
there is an example of how to do this in ?svytotal
svytotal( ~interaction( var1 , var2 ) , design )
Upvotes: 3