Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Re: Axis label


From   Oliver Jones <ojones@wiwi.uni-bielefeld.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: Axis label
Date   Wed, 13 Apr 2011 11:54:29 +0200

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.

Thank you,
Arti


*
*   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/

--
Universität Bielefeld
Fakultät für Wirtschaftswissenschaften
Lehrstuhl für Ökonometrie und Statistik
- - -
Bielefeld University
Faculty of Business Administration and Economics
Chair of Econometrics and Statistics
- - -
Raum / room:  V9-110
Tel / phone:  +49 (0)521 106 4871
--
*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index