0

Unfortunately I cannot sent you the dataset due to ethical reasons but I am trying to create a catplot of categorical variables. All the categorical variables are Likert responses.

There are 18 of them labelled: psq1 psq2 psq3 psq4 psq5 psq6 psq7 psq8 psq9 psq10 psq11 psq12 psq13 psq14 psq15 psq16 psq17 psq18

If you look on graph.png that is how psq1 looks on a catplot using the code:

catplot psq7 , asyvars stack percent over( psq_pubpriv) percent

graph.png

I want to move the public and private bars so that they are horizontal to each other and then stack all the psq on top of each other with the same axes. This is shown in psq.png.

psq.png

Another issue is that the title gets cut off of the y-axis label. I would like to make that text wrap and appear in two lines so it is all visible.

I would also want to change the color scheme, so that agree and strongly agree are shades of green, strongly disagree and disagree are shades of red and uncertain is blue

Nick Cox
  • 35,529
  • 6
  • 31
  • 47
Epijam
  • 11
  • 2

1 Answers1

1

The strategy if data cannot be posted is simple, and should be clear to any programmer: think up a similar problem with fake data or a public dataset.

catplot is from SSC: see the Stata tag wiki for the request to explain any community-contributed command that you use (as well as the advice just given).

Your data structure is unfriendly for what you want. An answer is to reshape long so that fewer variables are in play.

Much of this code is just setting up a fake dataset.

clear 
set obs 100 
set seed 2803 

label def whatever 1 "strongly agree" 2 agree 3 uncertain 4 disagree 5 "strongly disagree"

forval j = 1/5 { 
    gen psq`j' = runiformint(1, 5)
    label val psq`j' whatever 
}

gen public = runiform() > 0.5 
label def public 1 public 0 private 
label val public public 

gen id = _n
reshape long psq, i(id) j(which)
label val psq whatever 

set scheme s1color 
local toshow  "absurdly long title shown vertically that is unfriendly to readers" 
catplot psq which, percent(which public)  asyvars stack by(public, note("") l1title(`"`toshow'"')) 

enter image description here

On the extra details:

Your axis title is too long to show readably. Don't do that then! is sincere and serious advice. Otherwise use the Graph Editor. (I tried the usual work-around of using

`" "part 1" "part 2" "' 

but couldn't get it to work. As catplot passes that code directly to graph hbar, it may be a limitation of the latter that this isn't accepted.)

A colour scheme mixing red and green is seriously to be avoided. Difficulty distinguishing red and green is the most common kind of difficulty people have with colours (so-called colour blindness). Otherwise, please use the help.

Nick Cox
  • 35,529
  • 6
  • 31
  • 47