Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Using postfile to save single observations from a dataset


From   Nick Baker <nb419@cam.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   st: Using postfile to save single observations from a dataset
Date   28 Mar 2013 15:37:32 +0000

Hi all,

I currently have a time series dataset where the variables are the returns of several hundred mutual funds:

	Date	retfund1	retfund2
1	2006m1	-12.38985	10.39785
2	2006m2	-8.219995	9.54027
3	2006m3	5.497518	-5.947091
4	2006m4	-0.9465399	-2.846269
5	2006m5	2.219898	-12.51931
6	2006m6	0.4326888	-2.443768

What I want to do is to get these data into a long form with information on lagged returns:

FundID	Date	ret(t-1)	ret(t-2)
1	2006m1	.	.
1	2006m2	-12.38985	.
1	2006m3	-8.219995	-12.38985
1	2006m4	5.497518	-8.219995
1	2006m5	-0.9465399	5.497518
1	2006m6	2.219898	-0.9465399
2	2006m1	.	.
2	2006m2	10.39785	.
2	2006m3	9.54027	10.39785
2	2006m4	-5.947091	9.54027
2	2006m5	-2.846269	-5.947091
2	2006m6	-12.51931	-2.846269


Currently, for each fund I am generating variables of lagged returns and am then attempting to save each observation to a seperate dataset using postfile within a forvalues loop over the date range. However the resulting postfile does not contain a single observation. Has anyone else had a similar problem? Is there a way to do this without attempting to loop over obsevations?

Many Thanks,
Nicholas Baker



*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index