Statalist The Stata Listserver


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

Re: st: How to create a new variable which contains the response from another member


From   "Svend Juul" <SJ@SOCI.AU.DK>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: How to create a new variable which contains the response from another member
Date   Mon, 5 Mar 2007 09:28:56 +0100

Chiungya wrote:

I ... would like to use it to analyze a set of dyadic data. 
The data is as following:

Group    member        V1
 1       1            3.2
 1       2            4.5
 2       1            3.1
 2       2            3.3
 3       1             .
 3       2            2.3

I wish to generate a new variable--V2 in which responses from V1
are exchanged within a group. So, it should look like this:

Group         member          V1      V2
 1              1            3.2     4.5
 1              2            4.5     3.2
 2              1            3.1     3.3
 2              2            3.3     3.1
 3              1             .      2.3
 3              2            2.3      .
-----------------------------------------------------------------

Use explicit subscripting (see -help subscripting-) to get 
information from neighbour observations:

   sort group member
   generate v2=v1[_n+1] if group==group[_n+1] & member==1
   replace v2=v1[_n-1] if group==group[_n-1] & member==2

Hope this helps
Svend

__________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone: +45 8942 6090
Home:  +45 8693 7796
Email: sj@soci.au.dk
__________________________________________ 

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index