I am running Stata/MP v. 14.2, on a Windows10 PC with a I7-600 Quad CPU @3.41 GHz, with 32GB of installed memory and a 64-bit operating system. The file I am trying to process ("Z:\30firmsample.dta") is 52MB. But, I am computing a lot of covariances within a loop using this panel (state, year, firm, month) data set. My program has been running about 2 days now and the has completed 6 out of the 25 loop iterations. I have been monitoring the memory usage, and what is interesting/disturbing is that memory usage is rising over time. Stata's usage began around 5GB, and now it is over 12GB. At this rate, the program will probably not finish since it will run out of memory - despite a "clear" command each time the loop begins. I'm thinking there is very likely a much more efficient method to accomplish my goal (sequentially updating the variable "sum_r"). Thanks for any suggestions. My code follows:
forvalues i=1988/2013{
clear
use "Z:\30firmsample.dta", clear
keep if year==`i'
egen s1=max(state)
local n=s1
forvalues s=1/`n'{
use "Z:\data\30firmsample.dta", clear
keep if year==`i'
keep if state==`s'
keep mreturn month year state firm_order
reshape wide mreturn, i(month) j(firm_order)
corrci mreturn*, saving(corr`i'`s'.dta,replace)
use corr`i'`s',clear
egen sum_r=sum(r)
replace sum_r=2*sum_r
keep sum_r
duplicates drop sum_r,force
gen state=`s'
gen year=`i'
use "Z:\30firmsample.dta", clear
qui save "Z:\corr_within`i'`s'.dta",replace
append using "Z:\corr_within.dta"
save "Z:\corr_within.dta",replace
}
}
forvalues i=1988/2013{
clear
use "Z:\30firmsample.dta", clear
keep if year==`i'
egen s1=max(state)
local n=s1
forvalues s=1/`n'{
use "Z:\data\30firmsample.dta", clear
keep if year==`i'
keep if state==`s'
keep mreturn month year state firm_order
reshape wide mreturn, i(month) j(firm_order)
corrci mreturn*, saving(corr`i'`s'.dta,replace)
use corr`i'`s',clear
egen sum_r=sum(r)
replace sum_r=2*sum_r
keep sum_r
duplicates drop sum_r,force
gen state=`s'
gen year=`i'
use "Z:\30firmsample.dta", clear
qui save "Z:\corr_within`i'`s'.dta",replace
append using "Z:\corr_within.dta"
save "Z:\corr_within.dta",replace
}
}
Comment