Code:
clear input double(lpermno fyear) long apdedate float apdedateF90 str11 Station 10001 2010 18627 18537 "7252454853" 10001 2011 18992 18902 "7252454853" 10001 2012 19358 19268 "7252454853" 10001 2013 19723 19633 "7252454853" 10001 2014 20088 19998 "7252454853" 10001 2015 20453 20363 "7252454853" 10001 2016 20819 20729 "7252454853" 10002 2003 16070 15980 "99819699999" 10002 2004 16436 16346 "99819699999" 10002 2005 16801 16711 "99819699999" 10002 2006 17166 17076 "99819699999" 10002 2007 17531 17441 "99819699999" 10002 2008 17897 17807 "99819699999" 10002 2009 18262 18172 "99819699999" 10012 2003 16130 16040 "72297793184" end format %d apdedate format %td apdedateF90
Code:
clear input str11 Station float(temp Date) "72297793184" 56.7 17965 "72297793184" 67.9 21474 "72297793184" 59.1 16530 "72297793184" 63.6 17686 "72297793184" 59.7 18344 "72297793184" 62.6 16368 "72297793184" 57.7 18366 "72297793184" 58.8 17999 "72297793184" 61.4 19115 "72297793184" 61.4 21277 "72297793184" 71.1 18826 "72297793184" 61.1 19661 "72297793184" 69.4 21368 "72297793184" 62.4 20198 "72297793184" 65.9 16940 "72297793184" 63.9 19851 "72297793184" 66.4 14466 "72297793184" 60.6 17678 "72297793184" 64.8 17465 "72297793184" 60.3 14599 end format %td Date
My code is :
Code:
clear
cd "C:\Data"
use "Forloop.dta"
local obs = _N
forvalue Num = 1(1)`obs'{
display `Num'
global StartDate=apdedateF90[`Num']
display $StartDate
global EndDate=apdedate[`Num']
display $EndDate
global StationName="Station[`Num']"
display $StationName
use "NOAP.dta"
display $StationName
keep if Station==$StationName
keep if inrange(Date,$StartDate,$EndDate)
cd "C:\TempDta"
save `Num',replace
cd "C:\Data"
use "Forloop.dta",clear
}
Code:
7252454853 *Before the use "NOAP.dta" 01001099999 *After the use "NOAP.dta"
Why the value of the StationName is different before and after the use "NOAP.dta" ?
How to keep its value constant after use "NOAP.dta " ?
Thanks for your help.
0 Response to Why the local value in a loop changes after use another data-set ?
Post a Comment