Hi,
my datasheet contains 5000 observations with dichotomous variables smoking, alcohol, f_v intake, physical activity, and obesity. I also have age (coded 1-5), education (coded 1-5) and residence (1-3). I want to calculate the percentage of each dichotomous variable by age, education and residence categories and save the percentage in the same spreadsheet under the new variable names. For that, I first calculated the percentage separately and transferred them to the spreadsheet using the following command
input str16 factor male female age1 age2 age3 age4 age5 edu1 edu2 edu3 edu4 edu5 mountain hill tarai
"Cigarette smoking" 8.44 3.43 2.63 6.43 5.41 8.31 10.02 6.46 6.14 5.41 6.57 4.61 5.21 7.23 4.83
"Alcohol consumption" 6.74 3.61 2.97 5.71 4.79 6.85 7.68 6.48 3.85 5.29 5.92 5.56 4.74 6.16 4.06
"Low fruit and vegetable intake" 96.19 94.54 96.65 94.44 95.55 95.11 94.68 93.87 95.19 96.03 95.74 96.17 95.87 94.65 95.69
"Low physical activity" 76.91 80.72 82.80 81.92 75.04 75.61 78.51 89.48 83.31 73.58 69.21 71.38 81.91 76.26 77.05
"Overweight/obesity" 7.04 5.25 10.31 6.01 3.99 5.21 3.31 10.84 4.69 5.49 3.41 9.51 5.56 7.12 3.77
Is there any easy ways (macro or loop) to do that?
my datasheet contains 5000 observations with dichotomous variables smoking, alcohol, f_v intake, physical activity, and obesity. I also have age (coded 1-5), education (coded 1-5) and residence (1-3). I want to calculate the percentage of each dichotomous variable by age, education and residence categories and save the percentage in the same spreadsheet under the new variable names. For that, I first calculated the percentage separately and transferred them to the spreadsheet using the following command
input str16 factor male female age1 age2 age3 age4 age5 edu1 edu2 edu3 edu4 edu5 mountain hill tarai
"Cigarette smoking" 8.44 3.43 2.63 6.43 5.41 8.31 10.02 6.46 6.14 5.41 6.57 4.61 5.21 7.23 4.83
"Alcohol consumption" 6.74 3.61 2.97 5.71 4.79 6.85 7.68 6.48 3.85 5.29 5.92 5.56 4.74 6.16 4.06
"Low fruit and vegetable intake" 96.19 94.54 96.65 94.44 95.55 95.11 94.68 93.87 95.19 96.03 95.74 96.17 95.87 94.65 95.69
"Low physical activity" 76.91 80.72 82.80 81.92 75.04 75.61 78.51 89.48 83.31 73.58 69.21 71.38 81.91 76.26 77.05
"Overweight/obesity" 7.04 5.25 10.31 6.01 3.99 5.21 3.31 10.84 4.69 5.49 3.41 9.51 5.56 7.12 3.77
Is there any easy ways (macro or loop) to do that?
Comment