Statalist


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

RE: st: RE: sort on month


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: sort on month
Date   Tue, 8 Sep 2009 14:38:08 +0100

Show us the result of 

. describe month int_month 

. tab month, missing  

. tab int_month, missing 

Nick 
[email protected] 

qing ye


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


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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index