Statalist


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

Re: st: data management - sets of two lines into single line observation


From   "Scott Merryman" <[email protected]>
To   [email protected]
Subject   Re: st: data management - sets of two lines into single line observation
Date   Thu, 8 Nov 2007 06:43:23 -0600

On Nov 8, 2007 5:32 AM, b. water <[email protected]> wrote:
> dear all,
>
> stata 8.2,
>
> would appreciate advice on how the following data management transformation can be undertaken:
>
> at the moment data look like this:
>
> Epid    Att     Ned     Yag     Pallad
> Gord    Molb    Nur     Zn
> Yes     5       twice   Off     Present
> 2       3       PRN     no
> No      4       no      On      Present
> 0       1       no      yes
> .       .       .       .       .
> .       .       .       .
> .       .       .       .       .
> .       .       .       .
> Yes     5       twice   Off     Present
> 2       3       PRN     no
> No      4       no      On      Present
> 0       1       no      yes
>
> i want to change it so it looks like this:
>
> Epid    Att     Ned     Yag     Pallad  Gord    Molb    Nur     Zn
> Yes     5       twice   Off     Present 2       3       PRN     no
> No      4       no      On      Present 0       1       no      yes
> .
> .
> .
> .
> Yes     5       twice   Off     Present 2       3       PRN     no
> No      4       no      On      Present 0       1       no      yes
>
>

Like this?

clear
tempfile foo1 odd even
input str4 Epid str4 Att str5 Ned str3 Yag str7 Pallad
Gord    Molb    Nur     Zn
Yes     5       twice   Off     Present
2       3       PRN     no
No      4       no      On      Present
0       1       no      yes
end
l
save `foo1',replace
keep if mod(_n,2)
drop Pall
ds
foreach l in `r(varlist)' {
 local a `=`l'[1]'
 rename `l'  `a'
}
drop in 1
save `odd', replace
use `foo1',clear
keep if ! mod(_n,2)
save `even', replace
merge using `odd'
drop _m
l

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