Statalist The Stata Listserver


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

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


From   "Chiung-Ya Tang" <chiungya.tang@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: RE: How to create a new variable which contains the response from another member
Date   Tue, 6 Mar 2007 13:23:13 -0500

Many thanks to Austin, Klaus, and Svend for explaining to me.

I found it especially helpful when example syntax and the associated
terminologies such as explicit subscripting were referred in your
responses. I was able to find further information and applied them
correctly. --- Chiung-Ya


-------------------------------------------------------------------------------------
Below is a summary of approaches to my question.
In order to generate v2 as presented below

    ID   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      .


Austin suggested:

     bys ID (Member): g v2=v1[3-_n]


and Klaus and Svend shared their approaches:

     gen v2=.
     by ID, sort: replace v2=v1[_n+1] if v2==.
     by ID: replace v2=v1[_n-1] if v2==.


     sort ID Member
     generate v2=v1[_n+1] if ID==ID[_n+1] & Member==1
     replace v2=v1[_n-1] if ID==ID[_n-1] & Member==2
*
*   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