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
[email protected]
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/