<>
-encode- is the wrong tool, as it assigns numeric codes arbitrarily. You
definitely want to -destring-. Note the difference in the example below:
*************
clear*
inp str30(companyan id month)
"Bank of Bolton" 20000 1
"Bank of Bolton" 20000 10
"Bank of Bolton" 20000 11
"Bank of Bolton" 20000 12
"Bank of Bolton" 20000 2
"Bank of Bolton" 20000 3
"Bank of Bolton" 20000 4
end
compress
list, noobs
encode month, gen(newmonth)
sort newmonth
l, noo
destring, replace
sort month
l, noo
*************
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von qing ye
Gesendet: Dienstag, 8. September 2009 15:34
An: [email protected]
Betreff: Re: st: RE: sort on month
hi, Nick
I did transfer the month variable to interger variable with :
encode month, generate(int_month)
recast int int_month
and sort on int_month gives the same answer
destring does not work: see the following error message
. destring month, replace
month contains nonnumeric characters; no replace
. destring int_month, replace
int_month already numeric; no replace
Thanks
Qing
2009/9/8 Nick Cox <[email protected]>:
> Your -month- is presumably a string variable. For strings, "10" < "2", as
string sorts are by dictionary order.
>
> . d month
>
> will show you.
>
> If so, -destring month, replace-.
>
> A big and common misunderstanding is that changing the -format- changes
the way data are held. -format- changes the way data are shown.
>
> Nick
> [email protected]
>
> qing ye
>
> I was trying to sort the dataset on one variable which indiates
> months of the year.
> strangly, month 10, 11 and 12 always comes ahead of month 2 and the
> other months, anybody know why?
>
> I have formated the variable to be integer, still does not work.
>
> companyan id month
> Bank of Bolton 20000 1
> Bank of Bolton 20000 10
> Bank of Bolton 20000 11
> Bank of Bolton 20000 12
> Bank of Bolton 20000 2
> Bank of Bolton 20000 3
> Bank of Bolton 20000 4
>
>
> *
> * 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/
*
* 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/