<>
Quang should be able to adapt Sergiy`s convenient solution to his needs.
Note that it is not strictly necessary to do this with a -tempfile- in case
you are uncomfortable with it. Just -save- it to a permanent file then.
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Sergiy Radyakin
Gesendet: Mittwoch, 8. April 2009 17:42
An: [email protected]
Betreff: Re: st: AW: How to add the same block of data to every individual
A better way would be to use -joinby-.
clear
input byte id byte x
1 4
2 6
3 7
end
generate dummy=1
preserve
clear
input str1 y byte z
a 7
b 8
c 9
end
gen dummy=1
tempfile mrg
save `"`mrg'"'
restore
joinby using `"`mrg'"'
drop dummy
sort id y
list, sepby(id)
Best wishes,
Sergiy Radyakin
PS: variable dummy (substitute any name, which is not in either of
your datasets) is needed here because otherwise Stata complains that
there is no common variable to join by. Perhaps it is a sensible
default behaviour, when there is nothing to join by, just attach one
dataset to each observation of the other??
On Wed, Apr 8, 2009 at 11:31 AM, Quang Nguyen <[email protected]> wrote:
> Thanks Martin for such an excellent solution. Actually, the block of
> data is a (6x35) matrix. Can you suggest a somewaht better procedure?
>
> Many thanks!
>
>
> On Wed, Apr 8, 2009 at 5:14 AM, Martin Weiss <[email protected]> wrote:
>>
>> <>
>>
>> It really depends where you want to take this exercise next, but here is
a
>> shot at the prob:
>>
>> *************
>> clear*
>>
>> inp id x
>> 1 4
>> 2 6
>> 3 7
>> end
>>
>> expand 3
>>
>> bys id: g str1 y="a"
>> by id: replace y="b" if _n==2
>> by id: replace y="c" if _n==3
>> by id : egen float z = seq(), from(1) to(3) block(1)
>>
>> l, noo sepby(id)
>> *************
>>
>>
>>
>> HTH
>> Martin
>>
>> -----Ursprüngliche Nachricht-----
>> Von: [email protected]
>> [mailto:[email protected]] Im Auftrag von Quang Nguyen
>> Gesendet: Mittwoch, 8. April 2009 17:00
>> An: [email protected]
>> Betreff: st: How to add the same block of data to every individual
>>
>> Dear All:
>>
>> Suppose I have the following data set:
>>
>> id x
>> 1 4
>> 2 6
>> 3 7
>> ..................
>>
>> and a "data block" as follows:
>>
>> y z
>> a 7
>> b 8
>> c 9
>>
>> Do you know how I can add this data block to every individual in the
>> idividial data set. After adding, the new data set will look like the
>> following:
>>
>> id x y z
>> 1 4 a 7
>> 1 4 b 8
>> 1 4 c 9
>> 2 6 a 7
>> 2 6 b 8
>> 2 6 c 9
>> ----------------------------
>>
>> Many thanks!
>>
>>
>>
>> --
>> "My father gave me the greatest gift anyone could give another person,
>> he believed in me." - Jim Valvano
>> *
>> * For searches and help try:
>> * http://www.stata.com/help.cgi?search
>> * http://www.stata.com/support/statalist/faq
>> * http://www.ats.ucla.edu/stat/stata/
>>
>>
>> *
>> * For searches and help try:
>> * http://www.stata.com/help.cgi?search
>> * http://www.stata.com/support/statalist/faq
>> * http://www.ats.ucla.edu/stat/stata/
>>
>
>
>
> --
> "My father gave me the greatest gift anyone could give another person,
> he believed in me." - Jim Valvano
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/