Closing threads so neatly is welcome. But other comment is
possible. If your observations are really dyads, -reshape-
to a different data structure may be best in the long run.
rename v1 v
reshape wide v, i(ID) j(Member)
Nick
[email protected]
Chiung-Ya Tang
> 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.
>
>
> --------------------------------------------------------------
> -----------------------
> 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/