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: Re:


From   Jieyu Wang <[email protected]>
To   [email protected]
Subject   st: Re:
Date   Wed, 6 Apr 2011 12:39:20 -0500

Dear Arlene,

For the first question, you may want to first have a variable for year
and also have a numeric date variable date, for example. Then,  you
may use a command like -bysort year (date time) : keep if _n==_N-.

For the second question, something similar to -bysort year date: egen
daymean=mean(price)- would work.

Here is an example (year is the year, date could be the numeric date,
time represents different transaction in the day):

******************
clear
input year date time price
2000	1	10	1000
2000	1	20	2000
2000	2	10	1000
2000	2	20	2000
2001	10	100 10000	
2001	10	200	20000
2001	20	100 10000	
2001	20	200	20000

end

list

preserve

bysort year (date time) : keep if _n==_N
list

restore


preserve

bysort year date: egen daymean=mean(price)
drop time price
bysort year date: keep if _n==_N
list

restore
********************

Hope it helps.


2011/4/4 yi yang <[email protected]>:
> Hi everyone,
> We have met a data processing problem.
>
> We now have a series of daily trading data for all stocks listed from year 2000 to 2011. Our assignments are:
>
> (1) For each stock, keep only the data on the last trading day of each year;
>
> (2) For each year, accumulate the daily trading data of single stock as to obtain the mean value as the final trading data of this stock.
>
> As to the first requirement, we find it hard to locate the last trading day of each year, since it may be December 31th, or December 29,th or else.
>
> As to the second requirement, we have no idea which function or order to use as to accumulate the daily data, and finally count the mean value.
>
> Could anyone kindly help us to locate the target record, or to tell us how to compute the mean value?
>
> Thank you and best wishes!
>
>
> Arlene Young
>
>
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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