Statalist The Stata Listserver


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

Re: st: Re: RE: Re: How Can I Create the Variable x?


From   "Raphael Fraser" <[email protected]>
To   [email protected]
Subject   Re: st: Re: RE: Re: How Can I Create the Variable x?
Date   Mon, 29 Jan 2007 08:37:52 -0500

Your assumption was indeed correct. Thank you all.

On 1/29/07, Michael Blasnik <[email protected]> wrote:
Since he didn't actually state how x is defined (I almost hit the delete
because of this omission), but did give examples sorting on id bsid, I
assumed that his example had a small error in that 2 11 should be before 2
43.  If he really wants the ordering of id bsid unchanged in its currently
unsorted way , then this should work:

bysort id: gen myorder=_n
bysort id (myorder): gen x=sum(bsid!=bsid[_n-1])

Michael

----- Original Message -----
From: "Nick Cox" <[email protected]>
To: <[email protected]>
Sent: Monday, January 29, 2007 6:55 AM
Subject: st: RE: Re: How Can I Create the Variable x?


> That doesn't match Raphael's example, as
>
> 2 43
>
> and
>
> 2 11
>
> would be categorised differently. The question
> is thus whether he minds.
>
> Nick
> [email protected]
>
> Michael Blasnik
>
>> I think this does what you want:
>>
>> bysort id (bsid): gen x=sum(bsid!=bsid[_n-1])
>
> Raphael Fraser
>
>> >I need help in creating the var x.
>> >
>> > id bsid  x
>> > 1  22    1
>> > 1  22    1
>> > 1  52    2
>> > 1  87    3
>> > 2  43    1
>> > 2  43    1
>> > 2  11    2
>> > 3  28    1
>> > 4  33    1
>> >
>> > I have tried,
>> > bysort id bsid: gen x = _n
>> > bysort id (bsid): gen x = _n

*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index