Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Arti Rayit <arti.rayit@yahoo.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Re: Axis label |

Date |
Wed, 13 Apr 2011 11:14:36 +0100 (BST) |

Nick, Oliver, Many thanks for your assistance. The wealth of knowledge on this list is superb. Art ----- Original Message ---- From: Nick Cox <njcoxstata@gmail.com> To: statalist@hsphsun2.harvard.edu Sent: Wed, 13 April, 2011 10:05:12 Subject: Re: st: Re: Axis label As Oliver says, in the example the data are already sorted in the right order. That being so, labmask sid, values(parm) is a shorter solution yet. (As before, -labmask- is from SJ.) Nick On Wed, Apr 13, 2011 at 10:54 AM, Oliver Jones <ojones@wiwi.uni-bielefeld.de> wrote: > Hi, > > even so Nick already gave an solution, here is an example of how I would > have done it (before seeing Nick's solution). > > ************* begin example ******************* > clear > * Create some example variable > set obs 3 > gen str5 parm = "a" > replace parm = "b" in 2 > replace parm = "c" in 3 > list > gen qvs = rnormal() > > * Asuming the data are sorted the way you want them you can just > * create an id variable > gen int id = _n > > * Make a label out of you string variable > levelsof parm > tokenize `"`r(levels)'"' > local i = 0 > while "`1'" != "" { > local i = `i' + 1 > dis `i' > dis "`1'" > label define lbl_parm `i' "`1'", modify > macro shift > } > > * attach the label to your id variable > label values id lbl_parm > > list > > tw scatter qvs id, xlab(, valuelabel) > > exit > ************* end example ******************* > > Best > Oliver > > Am 13.04.2011 11:12, schrieb Arti Rayit: >> >> I have a dataset which has a str5 variable 'parm' of the form 1-2, 1-3, >> 1-4 etc >> and I want to use this as the variable on the x axis of a twoway scatter >> plot. I >> have converted this to numeric: >> >> encode parm,gen(id) label(parm) >> twoway (scatter qvs id), xlabel(, valuelabel) >> >> but the new variable has the sort order based on parm: >> parm estimate p qvs sid id | >> |----------------------------------------------------| >> 1. | 1-2 125.5616 3.83e-29 .0001 1 3 | >> 2. | 1-3 125.5616 3.83e-29 .0001 2 4 | >> 3. | 1-4 125.5616 3.83e-29 .0001 3 5 | >> 4. | 1-5 125.5616 3.83e-29 .0001 4 6 | >> 5. | 1-6 125.5616 3.83e-29 .0001 5 7 | >> |----------------------------------------------------| >> 6. | 1-7 125.5616 3.83e-29 .0001 6 8 | >> 7. | 1-8 125.5616 3.83e-29 .0001 7 9 | >> 8. | 1-9 125.5616 3.83e-29 .0001 8 10 | >> 9. | 1-10 125.5616 3.83e-29 .0001 9 1 | >> 10. | 1-11 125.5616 3.83e-29 .0001 10 2 >> >> which means the first plotted variable is 1-10 rather than 1-2. >> >> How can I sort this so that the plot sequence is 1-2, 1-3 etc. >> >> I am using Stata 11. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Re: Axis label***From:*Arti Rayit <arti.rayit@yahoo.com>

**Re: st: Re: Axis label***From:*Oliver Jones <ojones@wiwi.uni-bielefeld.de>

**Re: st: Re: Axis label***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**Re: st: Re: Axis label** - Next by Date:
**Re: st: Re: Axis label** - Previous by thread:
**Re: st: Re: Axis label** - Next by thread:
**Re: st: Re: Axis label** - Index(es):