Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: unique string variables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: unique string variables
Date   Mon, 15 May 2006 21:17:34 +0100

Rajesh gives various solutions. 

Among them, note that -bigtab- is 
a user-written command from SSC. 

Yet another user-written command in
the same territory is -groups-, also
from SSC. 

When your postings refer to non-official
commands, please say where they come from. 

Nick 
[email protected] 

Rajesh Tharyan
 
> sort appyear code location
> by appyear code location: gen noofloc=_N
> 
> gives
> 
> 
>      | appyear    code   location   noofloc |
>      |--------------------------------------|
>   1. |    1972   66735         CA         1 |
>   2. |    1972   71340        GBX         6 |
>   3. |    1972   71340        GBX         6 |
>   4. |    1972   71340        GBX         6 |
>   5. |    1972   71340        GBX         6 |
>      |--------------------------------------|
>   6. |    1972   71340        GBX         6 |
>   7. |    1972   71340        GBX         6 |
>   8. |    1972   75065        GBX         2 |
>   9. |    1972   75065        GBX         2 |
>  10. |    1972   76070        JPX         4 |
>      |--------------------------------------|
>  11. |    1972   76070        JPX         4 |
>  12. |    1972   76070        JPX         4 |
>  13. |    1972   76070        JPX         4 |
>  14. |    1972   76070         NJ         2 |
>  15. |    1972   76070         NJ         2 |
>      +--------------------------------------+
> 
> bigtab  appyear code location gives
> 
>   +--------------------------------------------------------------+
>   | appyear    code   location   freq     pct   cumfreq   cumpct |
>   |--------------------------------------------------------------|
>   |    1972   66735         CA      1    6.67         1     6.67 |
>   |    1972   71340        GBX      6   40.00         7    46.67 |
>   |    1972   75065        GBX      2   13.33         9    60.00 |
>   |    1972   76070        JPX      4   26.67        13    86.67 |
>   |    1972   76070         NJ      2   13.33        15   100.00 |
>   +--------------------------------------------------------------+
> 
> 
> 
> table code location, contents( freq ) by(appyear) gives 
> 
> ----------------------------------
> appyear   |        location       
> and code  |   CA   GBX   JPX    NJ
> ----------+-----------------------
> 1972      |
>     66735 |    1                  
>     71340 |          6            
>     75065 |          2            
>     76070 |                4     2
> ----------------------------------
> 
> Etc..
> 
> Hope this helps

Mazhar Islam
 
> I want to identify unique string variables within a
> subgroup. I pasted a portion of data below.
> Specifically I want to find how many locations a
> certain code operates in a certain year. I will
> appreciate any help.
> 
> appyear	code	location
> 1972	66735	CA
> 1972	71340	GBX
> 1972	71340	GBX
> 1972	71340	GBX
> 1972	71340	GBX
> 1972	71340	GBX
> 1972	71340	GBX
> 1972	75065	GBX
> 1972	75065	GBX
> 1972	76070	JPX
> 1972	76070	JPX
> 1972	76070	NJ
> 1972	76070	NJ
> 1972	76070	JPX
> 1972	76070	JPX

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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