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: Copying data from an observation to a different time period, using bysort


From   Clarice Martins <[email protected]>
To   [email protected]
Subject   st: Copying data from an observation to a different time period, using bysort
Date   Thu, 31 Oct 2013 17:25:25 -0200

Dear group,

I have been trying to solve a new issue in my dataset:  (I am using Stata 12, for Mac)

I am using command -bysort  varlist : command-
(but not sure if it is the best option)

The problem is to copy -quintile- observation to NEXT -yrmonth- , - if rtype=="buy_sell_period"-

*-------snapshot of dataset-----
co_id	ticker	name	rtype	yrmonth	rating	numericrating	return	quintile
2	AEDU3	ANHANGUERA	buy_sell_period	2007m8	BB	12	-0.02 .
2	AEDU3	ANHANGUERA	formation	2007m8	BB	12	0.32 1
2	AEDU3	ANHANGUERA	hold_period	2007m8	BB	12	0.32 .
2	AEDU3	ANHANGUERA	buy_sell_period	2007m9	BB	12	0.13 .
2	AEDU3	ANHANGUERA	formation	2007m9	BB	12	0.40 5
2	AEDU3	ANHANGUERA	hold_period	2007m9	BB	12	0.40 .	
*-------------

Expected result:

- In this case, the quintile 1 needed to go to 2007m9, buy_sell_period.
- And quintile 5 need to go to 2007m10, buy_sell_period (not shown)

I tried a mix of several things in these lines, but not quite getting the results needed:

    bysort co_id yrmonth (quintile) : generate quintile2 = quintile[_n-1] // the result is quintile copied in sequence not what is needed

I wonder if I need to change HRF dates to SIF dates? (Since sorting by -yrmonth- does produce a calendar order of months and year.)

Thank you all for your consideration,
Clarice



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