The intended purpose for this write-up is to explain the two new weighted prop.table functions in ussc.

The first, ussc::prop_survey_question(), calculates the weighted proportion for specified questions across both countries and spreads the results so that the resulting data frame is wide (i.e. corresponding US and Australian proportions for the question and answer are side-by-side). It works as follows:

f1 <- survey_data %>%
  prop_survey_question(questions = starts_with("stance_on_tarrifs")) %>%
  select(-description_au) %>%
  kable("html", digits = 0, booktabs = TRUE)

f1
description_us answer Australia United States Difference
stance on tariffs (general) Bad for the American economy 32 42 10
stance on tariffs (general) Good for the American economy 25 27 2
stance on tariffs (general) Neither good nor bad for the American economy 43 31 -12
stance on tariffs (trump influence) Bad for the American economy 40 41 1
stance on tariffs (trump influence) Good for the American economy 24 33 9
stance on tariffs (trump influence) Neither good nor bad for the American economy 36 26 -10

The sample group has already been specified for you. You do need to make note of the particular questions you want to select.

Keep in mind that the answer column has been coerced to a character variable. To turn it back into a factor, run the following function relevel_survey_answer:

survey_data %>%
  prop_survey_question(questions = starts_with("stance_on_tarrifs")) %>%
  relevel_survey_answer(c("Good for the American economy",
                          "Neither good nor bad for the American economy",
                          "Bad for the American economy")) %>%
  select(-description_au) %>%
  kable("html", digits = 0, booktabs = TRUE)
description_us answer Australia United States Difference
stance on tariffs (general) Good for the American economy 25 27 2
stance on tariffs (general) Neither good nor bad for the American economy 43 31 -12
stance on tariffs (general) Bad for the American economy 32 42 10
stance on tariffs (trump influence) Good for the American economy 24 33 9
stance on tariffs (trump influence) Neither good nor bad for the American economy 36 26 -10
stance on tariffs (trump influence) Bad for the American economy 40 41 1

Your data frame will reorder based on the factor levels in the answer column.

The second function, ussc::prop_grouped_survey_question() allows the user to group by two or more variables, like so:

f2 <- survey_data %>%
  prop_grouped_survey_question(questions = starts_with("sexual_harrassment"), partyid) %>%
  select(-description_au) %>%
  rename_all(~sub('Australia_|(United States_)', '', .x)) %>%
  rename("AU other/none" = `Other or none`)

knitr::kable(f2, digits = 0, booktabs = TRUE)
description_us answer Coalition Greens Labor AU other/none Democrat Independent Republican
degrees of sexual harrassment - men getting away with committing sexual harassment and assault A major problem 62 76 70 59 83 60 45
degrees of sexual harrassment - men getting away with committing sexual harassment and assault A minor problem 32 22 24 32 14 30 44
degrees of sexual harrassment - men getting away with committing sexual harassment and assault Not a problem 6 1 5 9 2 11 12
degrees of sexual harrassment - women making false claims about sexual harassment or assault A major problem 47 26 37 46 32 46 58
degrees of sexual harrassment - women making false claims about sexual harassment or assault A minor problem 46 42 50 46 43 41 36
degrees of sexual harrassment - women making false claims about sexual harassment or assault Not a problem 8 32 13 8 25 14 6
degrees of sexual harrassment - women not being believed about sexual harassment and assault A major problem 52 71 59 50 76 49 30
degrees of sexual harrassment - women not being believed about sexual harassment and assault A minor problem 37 25 33 33 21 32 48
degrees of sexual harrassment - women not being believed about sexual harassment and assault Not a problem 10 4 8 17 3 18 23

You can group by multiple variables, but keep in mind that the tables will get very wide and we will need to fit our output on a standard A4 paper.

Both functions return the description for the Australian survey and the American survey. The questions were often the exact same, so you can simply filter out a description column.

The column names will return information about the country and grouping variables. These, of course, should be cleaned up. I leave this up to the user.

Of course, you can pass other functions to the returned object. A pretty kable table can be pulled together quite quickly, e.g.

t <- f2 %>%
  select(-description_us,
         -`AU other/none`) %>%
  rename(" " = "answer") %>%
  knitr::kable("html", booktabs = T, digits = 0) %>%
  kableExtra::add_header_above(c(" " = 1,
                     "Australia" = 3,
                     "United States" = 3), bold = T) %>%
  kableExtra::group_rows(index = c("Men getting away with committing sexual harassment and assault" = 3,
                       "Women making false claims about sexual harassment or assault" = 3,
                       "Women not being believed about sexual harassment and assault" = 3))
t
Australia
United States
Coalition Greens Labor Democrat Independent Republican
Men getting away with committing sexual harassment and assault
A major problem 62 76 70 83 60 45
A minor problem 32 22 24 14 30 44
Not a problem 6 1 5 2 11 12
Women making false claims about sexual harassment or assault
A major problem 47 26 37 32 46 58
A minor problem 46 42 50 43 41 36
Not a problem 8 32 13 25 14 6
Women not being believed about sexual harassment and assault
A major problem 52 71 59 76 49 30
A minor problem 37 25 33 21 32 48
Not a problem 10 4 8 3 18 23