Statalist The Stata Listserver


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

RE: st: RE: table of strings


From   "David Harrison" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: table of strings
Date   Wed, 3 May 2006 08:44:50 +0100

You can do a pretty good job with a -reshape- followed by a -list-...

*setting up some data
input str1 union byte pol_dem
"a" 1
"b" 2
"c" 1
"d" 0
"e" 1
end

*now the real bit...
bysort pol_dem (union): gen row=_n
reshape wide union, i(row) j(pol_dem)
forvalues p=0/2 {
	char union`p'[varname] "pol_dem=`p'"
}
list union?, noobs subvarname div abbrev(9) 


The output for the above looks like:

  +-----------------------------------+
  | pol_dem=0 | pol_dem=1 | pol_dem=2 |
  |-----------+-----------+-----------|
  |         d |         a |         b |
  |           |         c |           |
  |           |         e |           |
  +-----------------------------------+

I never like to cut and paste except as an absolute last resort!

Hope this helps

David

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Caleb
Southworth
Sent: 02 May 2006 19:06
To: [email protected]
Subject: Re: st: RE: table of strings

On Tue, 2 May 2006, Nick Cox wrote:

:The question in turn is what belongs in :a "cell" of the table?
-tabdisp- will :show you tables of strings, but if

I was too vague. Take these data:

. list union pol_ if pol_!=., str(30)

     +--------------------------------------------+
     | union                              pol_dem |
     |--------------------------------------------|
  1. | bakery and confectionery worke..         1 |
  2. | communications association; am..         2 |
  3. | state, county and municipal wo..         2 |
  9. | switch men                               1 |
 11. | boot and shoe workers                    0 |
     |--------------------------------------------|
 12. | plate printers, die stampers a..         1 |
 14. | glass bottle blowers                     1 |
 15. | painters, decorators and paper..         0 |
 16. | stove mounters                           1 |
 18. | photo- engravers                         1 |
     |--------------------------------------------|
 19. | mechanics and foremen of naval..         1 |
 22. | hatters, cap and millinery wor..         2 |
 24. | laundry and dry cleaning                 1 |
     +--------------------------------------------+

I want to make a table of unions (strings) by pol_id (categorical var):

. tabdisp pol_dem if pol_dem!=., c(union)

--------------------------------
  pol_dem |                union
----------+---------------------
        0 | boot and shoe worker
        1 | bakery and confectio
        2 | communications assoc
--------------------------------

Aside from a preference for the categorical variable being the columns,
"what belongs in a cell" is a list of all the cases (strings) for each
category. That is, the information from

. by pol_: list union

------------------------------------------------------------------------
-------
-> pol_dem = 0

     +---------------------------------------+
     |                                 union |
     |---------------------------------------|
  1. | painters, decorators and paperhangers |
  2. |                 boot and shoe workers |
     +---------------------------------------+

------------------------------------------------------------------------
-------
-> pol_dem = 1

     +-----------------------------------------------------------------+
     |                                                           union |
     |-----------------------------------------------------------------|
  1. | bakery and confectionery workers' international union; american |
  2. |                                                photo- engravers |
  3. |                                            glass bottle blowers |
  4. |                                                      switch men |
  5. |             mechanics and foremen of naval shore establishments |
     |-----------------------------------------------------------------|
  6. |                      plate printers, die stampers and engravers |
  7. |                                        laundry and dry cleaning |
  8. |                                                  stove mounters |
     +-----------------------------------------------------------------+

------------------------------------------------------------------------
-------
-> pol_dem = 2

     +--------------------------------------+
     |                                union |
     |--------------------------------------|
  1. |  state, county and municipal workers |
  2. | communications association; american |
  3. |   hatters, cap and millinery workers |
     +--------------------------------------+

Perhaps the answer is cut and paste.

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

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