Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Command for selecting values
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: Command for selecting values
Date
Wed, 30 Oct 2013 13:32:04 +0000
. bysort co_id (quintile) : replace quintile = quintile[1]
lets you "spread" the non-missing values of -quintile- to all
observations for each company. You can then select appropriate
companies freely.
For an introductory review of several tricks in this territory, see
SJ-11-2 dm0055 . . . . . . . . . . . . . . Speaking Stata: Compared with ...
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
Q2/11 SJ 11(2):305--314 (no commands)
reviews techniques for relating values to values in other
observations
Nick
[email protected]
On 30 October 2013 13:04, Clarice Martins <[email protected]> wrote:
> I am using Stata 12.1 for Mac.
>
> My problem is:
> - within a dataset (with the structure below), I need to -if rtype=="formation" & yrmonth == "`lev'" & quintile==1- , pick values from -rtype==buysell- but from same companies that are in the -if- selection.
>
> I thought of something like this for a code:
>
> *-------begin code------
> gen P1_sell = .
> levelsof yrmonth, local(levs)
>
>
> foreach lev of local levs {
> egen OK = anymatch(co_id) values (if rtype=="formation" & yrmonth == "`lev'" & quintile==1) //na aceita if ai dentro
> replace P1_sell = return if rtype=="buysell" & yrmonth == "`lev'" & co_id = anymatch(OK)
> drop temp
> }
> *-------end code------------
>
> But I know there is something missing to tell the code to pick values from other observations. I have been researching similar cases on the net, but no luck yet.
>
> Can anyone give me a hint???
>
> Thank you very much,
> Clarice
>
> *----dataset sample----
> clear
> input byte co_id str4 ticker str10 rtype str10 yrmonth double return byte quintile
> 1 ABCB formation jun2000 0.01 1
> 1 ABCB formation jul2000 0.01 1
> 1 ABCB formation aug2000 0.01 1
> 1 ABCB buysell jul2000 0.01 .
> 1 ABCB buysell aug2000 0.01 .
> 1 ABCB buysell sep2000 0.01 .
> 1 ABCB holding jan2001 0.01 .
> 1 ABCB holding feb2001 0.01 .
> 1 ABCB holding mar2001 0.01 .
> 2 AEDU formation jun2000 0.01 2
> 2 AEDU formation jul2000 0.01 2
> 2 AEDU formation aug2000 0.01 2
> 2 AEDU buysell jul2000 0.01 .
> 2 AEDU buysell aug2000 0.01 .
> 2 AEDU buysell sep2000 0.01 .
> 2 AEDU holding jan2001 0.01 .
> 2 AEDU holding feb2001 0.01 .
> 2 AEDU holding mar2001 0.01 .
> 3 AMBV formation jun2000 0.01 3
> 3 AMBV formation jul2000 0.01 3
> 3 AMBV formation aug2000 0.01 3
> 3 AMBV buysell jul2000 0.01 .
> 3 AMBV buysell aug2000 0.01 .
> 3 AMBV buysell sep2000 0.01 .
> 3 AMBV holding jan2001 0.01 .
> 3 AMBV holding feb2001 0.01 .
> 3 AMBV holding mar2001 0.01 .
> 4 FFFF formation jun2000 0.01 4
> 4 FFFF formation jul2000 0.01 4
> 4 FFFF formation aug2000 0.01 4
> 4 FFFF buysell jul2000 0.01 .
> 4 FFFF buysell aug2000 0.01 .
> 4 FFFF buysell sep2000 0.01 .
> 4 FFFF holding jan2001 0.01 .
> 4 FFFF holding feb2001 0.01 .
> 4 FFFF holding mar2001 0.01 .
> 5 BBBB formation jun2000 0.01 5
> 5 BBBB formation jul2000 0.01 5
> 5 BBBB formation aug2000 0.01 5
> 5 BBBB buysell jul2000 0.01 .
> 5 BBBB buysell aug2000 0.01 .
> 5 BBBB buysell sep2000 0.01 .
> 5 BBBB holding jan2001 0.01 .
> 5 BBBB holding feb2001 0.01 .
> 5 BBBB holding mar2001 0.01 .
> 6 MMMM formation jun2000 0.01 .
> 6 MMMM formation jul2000 0.01 .
> 6 MMMM formation aug2000 0.01 .
> 6 MMMM buysell jul2000 0.01 .
> 6 MMMM buysell aug2000 0.01 .
> 6 MMMM buysell sep2000 0.01 .
> 6 MMMM holding jan2001 0.01 .
> 6 MMMM holding feb2001 0.01 .
> 6 MMMM holding mar2001 0.01 .
> end
> *-------end--------
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/