Bookmark and Share

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]

st: Command for selecting values


From   Clarice Martins <martins.clarice@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Command for selecting values
Date   Wed, 30 Oct 2013 11:04:50 -0200

Hello, dear group!!

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index