stata - Sort by variable in twoway scatter. X-axis stays alphabetical and sort produces gibberish: why? -
i have 2 variables:
ie_ctotal cntry2
note: cntry2
encode
d version of string variable cntry
: don't know if may affecting things.
i want twoway scatter
of ie_ctotal
, cntry2
, , want sort scatter variable gdppc
,
twoway || scatter ie_ctotal cntry2, c(1) xlabel(,valuelabel)
the above without sort
works fine. once introduce sort
, however,
twoway || scatter ie_ctotal cntry2, c(1) sort(gdppc) xlabel(,valuelabel)
the graph turns gibberish, or rather connects according sort
, x axis remains alphabetical, making connections seem scribbled.
any ideas doing wrong?
note: don't want sort
original data, because advised in previous questions bad idea. want sort
data 1 graph.
there no reproducible example here, , not graph, possible guess problem.
you typing above
c(1)
which ill-advised, although stata right thing. better type
c(l)
which instructs stata join data points on graph in line. (nod @dimitriy v. masterov on detail.)
in first example, values of cntry2
define x axis.
as say, effect of sort(gdppc)
connect points in order of values lowest gdppc
highest. result not want.
here dopey reproducible example makes point.
. sysuse auto, clear (1978 automobile data) . scatter mpg weight, sort(price) c(l)
you want sort countries gdppc
order. sorting make
in stata's auto data according mpg
, plotting weight
. here foreign cars. it's not graph, sounds close in spirit want. solution requires installation of labmask
, search labmask
, download stata journal website.
sysuse auto, clear keep if foreign sort mpg gen obsno = _n labmask obsno, values(make) scatter weight obsno, xla(1/22, valuelabel ang(v) noticks) xtitle("")
in nutshell: sort()
option here defines connection order; doesn't map x axis variable reshuffled version. need before graphics.
update in fact, can same graph without prior manipulation:
graph dot (asis) weight if foreign, over(make, sort(mpg) label(ang(v))) vertical linetype(line) lines(lc(none))
this going along op's interest in putting labelled categories on x axis. graph easier read put them on y axis: text can read left right. that, omit vertical
above: default graph dot
. although command above omits guide lines setting colour none
, thin light colour guide lines can help.
Comments
Post a Comment