Code:
. quietly : levelsof stockidentifier , local(stocknames) macro length exceeded
Any idea how to resolve the problem?
. quietly : levelsof stockidentifier , local(stocknames) macro length exceeded
Any idea how to resolve the problem?
Code: // create easy to reproduce example data: trading dates clear input str10(trading_days) "01/02/2016" "01/03/2016" "01/04/2014" "01/04/2015" "01/04/2016" "01/05/2014" "01/05/2015" "01/06/2015" "01/06/2016" "01/07/2014" "01/07/2015" "01/07/2016" "01/08/2014" "01/08/2016" "01/09/2014" "01/09/2015" "01/09/2016" "01/10/2014" "01/10/2015" "01/11/2016" "01/12/2014" "01/12/2015" "01/12/2016" "02/01/2014" "02/01/2015" "02/02/2015" "02/02/2016" "02/03/2015" "02/03/2016" end // create a true date variable generate truedate=date(trading_days,"DMY") format truedate %td sort truedate // temporarily save tempfile dates save `"`dates'"' // create easy to reproduce example data: stock names and values clear input str25(stockidentifier) str10(date) date_ymd hightradefortheday lowtradefortheday lasttradefortheday "4DS.ASX" "24/02/2016" 20160224 .034 .03 .03 "4DS.ASX" "25/02/2016" 20160225 .03 .029 .029 "4DS.ASX" "26/02/2016" 20160226 .03 .029 .029 "4DS.ASX" "29/02/2016" 20160229 .029 .029 .029 "4DS.ASX" "01/03/2016" 20160301 .03 .029 .03 "4DS.ASX" "02/03/2016" 20160302 .033 .032 .032 "88EO.ASX" "02/07/2015" 20150702 .005 .004 .005 "88EO.ASX" "03/07/2015" 20150703 .005 .005 .005 "88EO.ASX" "06/07/2015" 20150706 .006 .005 .006 "88EO.ASX" "07/07/2015" 20150707 .005 .005 .005 "88EO.ASX" "08/07/2015" 20150708 .004 .004 .004 "88EO.ASX" "13/07/2015" 20150713 .005 .004 .005 "88EO.ASX" "15/07/2015" 20150715 .004 .004 .004 "88EO.ASX" "17/07/2015" 20150717 .005 .004 .005 "88EO.ASX" "22/07/2015" 20150722 .004 .004 .004 end format date_ymd %10.0g // create a true date variable generate truedate=date(date,"DMY") format truedate %td sort truedate // temporarily save tempfile stocks save `"`stocks'"' // save all names of stocks to local macro quietly : levelsof stockidentifier , local(stocknames) local stockcount : word count `stocknames' // duplicate trading dates for each stock use `"`dates'"' , clear generate stockidentifier="" local firstobs=1 local lastobs=_N local origN=_N expand `stockcount' foreach stockname of local stocknames { replace stockidentifier=`"`stockname'"' in `firstobs'/`lastobs' local firstobs=`firstobs'+`origN' local lastobs=`lastobs'+`origN' } keep truedate stockidentifier save `"`dates'"' , replace // join trading dates and stocks use `"`stocks'"' , clear joinby stockidentifier truedate using `"`dates'"' , unmatched(both) _merge(source) sort stockidentifier truedate // list data list , sepby(stockidentifier)
Comment