Hi Chiungya,
if you have no more than two members in a group, the following syntax
may work
with "[_n+1]" you can refers to the case in the following line
It's important that the data are sorted as in your example:
Group member V1
=3DE3=3D80=3D801 1 3.2
=3DE3=3D80=3D801 2 4.5
=3DE3=3D80=3D802 1 3.1
=3DE3=3D80=3D802 2 3.3
=3DE3=3D80=3D803 1 .
=3DE3=3D80=3D803 2 2.3
gen v2=3D.
*[_n+1] taking the values from the next line (that is person in the
group) in the data, [by group, sort] only when line below represents
person in the same group
by group, sort: replace v2=3Dv1[_n+1] if v2=3D=3D.
*[_n-1] taking the values from the line before in the data, [by group]
only when line above represents a person of the same group
by group: replace v2=3Dv1[_n-1] if v2=3D=3D.
If you have more persons in a group you have to make sure, that you
refer to the right case in a group.
For example, if you analyse families, and you want to relate both
parents, but not the children in a household, you have to know, who is
the partner of the respondent: say vars id (own id) and pid (id of partner)
sort group id
by group: replace v2=3Dv1[_n+1] if v2=3D=3D. & pid=3D=3Did[_n+1]
by group, sort: replace v2=3Dv1[_n-1] if v2=3D=3D. & pid=3D=3Did[_n-1]
if difference between id and pid >1 or <-1 you have to gone on like that
by group: replace v2=3Dv1[_n+2] if v2=3D=3D. & pid=3D=3Did[_n+2]
etc
Hope this helps,
Klaus
_________________________
Klaus Haberkern
Soziologisches Institut
Universit=E4t Z=FCrich
Andreasstrasse 15
CH-8050 Z=FCrich
Tel.: ++41-(0)44-635 23 43
E-Mail: [email protected]
Internet: www.suz.unizh.ch/ages
Chiung-Ya Tang schrieb:
> her member
> Date: Sun, 4 Mar 2007 20:06:50 -0500
> Message-ID: <002301c75ec2$8ebe21c0$6401a8c0@Saturdaynight>
> MIME-Version: 1.0
> Content-Type: text/plain;
> =3D09charset=3D3D"UTF-8"
> X-Mailer: Microsoft Office Outlook 11
> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
> Thread-Index: Acdewo3xDbzlOHAwQ/aMhHOZCSj6qg=3D3D=3D3D
> Content-Transfer-Encoding: 8bit
> X-MIME-Autoconverted: from quoted-printable to 8bit by hsphsun2.harvard.e=
du=3D
> id l2517LJ10855
> Sender: [email protected]
> Precedence: bulk
> Reply-To: [email protected]
> Errors-To: [email protected]
> Hi,
>
> I am learning STATA and would like to use it to analyze a set of dyadic d=
at=3D
> a. The data is as following:
>
> Group member V1
> =3DE3=3D80=3D801 1 3.2
> =3DE3=3D80=3D801 2 4.5
> =3DE3=3D80=3D802 1 3.1
> =3DE3=3D80=3D802 2 3.3
> =3DE3=3D80=3D803 1 .
> =3DE3=3D80=3D803 2 2.3
>
> I wish to generate a new variable--V2 in which responses from V1 are exch=
an=3D
> ged within a group. So, it should look like this:
>
> Group member V1 V2
> =3DE3=3D80=3D801 1 3.2 4.5
> =3DE3=3D80=3D801 2 4.5 3.2
> =3DE3=3D80=3D802 1 3.1 3.3
> =3DE3=3D80=3D802 2 3.3 3.1
> =3DE3=3D80=3D803 1 . 2.3
> =3DE3=3D80=3D803 2 2.3 .
>
>
> I searched commands as well information from Statalist archives but still=
h=3D
> aven't figured out how to do that correctly. While keeping learning new c=
om=3D
> mands, I definitely appreciate any help from you. Thank you.
>
> Sincerely,
> Chiungya
> =3DE3=3D80=3D80
> =3DE3=3D80=3D80
> =3DE3=3D80=3D80
> =3DE3=3D80=3D80
>
>
> *
> * 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/
>
>
*
* 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/