Statalist The Stata Listserver


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

RE: st: RE: table of strings


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: table of strings
Date   Wed, 3 May 2006 10:51:50 +0100

This is a neat trick. 

As an experiment, I tried to see how far you 
could get with just -separate-. 

input str1 union byte pol_dem
"a" 1
"b" 2
"c" 1
"d" 0
"e" 1
end

. separate union, by(pol_dem) shortlabel

              storage  display     value
variable name   type   format      label      variable label
-------------------------------------------------------------------------------
union0          str1   %9s                    pol_dem == 0
union1          str1   %9s                    pol_dem == 1
union2          str1   %9s                    pol_dem == 2

. foreach v of var union? { 
  2. char `v'[varname] "`: variable label `v''" 
  3. }

. list union? , subvarname abb(12)

     +--------------------------------------------+
     | pol_dem == 0   pol_dem == 1   pol_dem == 2 |
     |--------------------------------------------|
  1. |                           a                |
  2. |                                          b |
  3. |                           c                |
  4. |            d                               |
  5. |                           e                |
     +--------------------------------------------+

As David indicates, it seems that the -reshape- 
is needed to get what you want: no pain, no gain 
here. 


Nick 
n.j.cox@durham.ac.uk 

David Harrison
 
> 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 |           |
>   +-----------------------------------+
 

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index