Pedro Martins
> my data is shaped in the following way:
> c d
> a 1 2
> b 3 4
>
> and i would like to have it in this way:
> x a b c d
> 1 1 0 1 0
> 2 1 0 0 1
> 3 0 1 1 0
> 4 0 1 0 1
>
> that is, to transform both the variables and the
> cross-section observations
> into dummies
> any suggestions?
Perhaps some generalisation of this:
Pedro's example "data"
======================
input str1 what c d
"a" 1 2
"b" 3 4
end
l
Pedro's transformation
======================
expand 2
sort what
foreach v in a b {
gen `v' = what == "`v'"
}
tokenize c d
forval i = 1/2 {
bysort what : replace ``i'' = _n == `i'
}
l
1. expand 2 => expand #obs
2. "a b" => value list
3. "c d" => variable list
4. 1/2 => 1/#vars
Nick
n.j.cox@durham.ac.uk
*
* 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/