📄 memsize.ado
字号:
*! version 3.0.4 21nov199794
program define memsize
* touched by jwh
ChkVer
version 3.0
if "`*'"=="" { error 198 }
local obs 0
local width 0
local var 0
if "`2'"=="" {
local 2 "`1'"
local 1 "using"
}
if "`1'"=="using" {
quietly describe using `2', detail short
local obs = r(N)
local var = r(k)
local width = r(width)
}
else {
while "`1'"!="" {
if "`2'"=="" { error 198 }
confirm integer number `2'
if "`1'"=="int" {
local width = `width' + 2*`2'
local var = `var' + `2'
}
else if "`1'"=="byte" {
local width = `width' + `2'
local var = `var' + `2'
}
else if "`1'"=="long" | "`1'"=="float" {
local width = `width' + 4*`2'
local var = `var' + `2'
}
else if "`1'"=="double" {
local width = `width' + 8*`2'
local var = `var' + `2'
}
else if substr("`1'",1,3)=="str" {
local len = substr("`1'",4,.)
confirm integer number `len'
local width = `width' + `len'*`2'
local var = `var' + `2'
}
else if "`1'"=="obs" {
local obs "`2'"
}
else { error 198 }
mac shift 2
}
}
di _n _col(8) in gr "variables:" _col(38) in ye "`var'" _n /*
*/ _col(8) in gr "width:" _col(38) in ye "`width'"
if `obs' == 0 { exit }
di _col(8) in gr "observations:" _col(38) in ye "`obs'" _n /*
*/ _col(8) in gr "data set size:" _col(38) in ye /*
*/ =(max(int((`obs')*(`width')/1024),1)),"k" _n
quietly desc, detail short
local os = r(N_max)
local vs = r(k_max)
local ws = r(widthmax)
if `obs'<`os'-10 & `var'<`vs'-5 & `width'<`ws'-10 {
di _col(8) in gr /*
*/ "data will fit in current partition, but you could"
local FIT "yes"
}
else {
di _col(8) in red /*
*/ "data will not fit in current partition"
}
if `width'*`obs' > `ws'*`os'-10000 {
di _col(8) in red "insufficient total memory"
exit
}
di _n in gr _col(39) "approx." _col(49) "free float free" _n /*
*/ _col(8) "command" _col(39) "maxobs" /*
*/ _col(49) "variables" _col(64) "obs" _n /*
*/ _col(8) _dup(59) "-"
if "`FIT'"=="yes" {
di in gr " `7'" _col(8) "(do nothing)" /*
*/ _col(38) in ye /*
*/ %7.0f =`os' _col(50) %6.0f =int((`ws'-`width')/4) /*
*/ _col(60) %7.0f =(`os'-`obs')
}
local W = int(sqrt(`ws'*`os'*`width'/`obs'))
_crcmem1 `os' `ws' `W' `width' `var' `obs' F4
local W = int((`ws'*`os'-30000)/(`obs'+100))
_crcmem1 `os' `ws' `W' `width' `var' `obs' F5
local W = `width' + 20
_crcmem1 `os' `ws' `W' `width' `var' `obs' F6
end
program define _crcmem1
version 3.0
if `3' > 3098 { local 3 "3098" }
local O = int((`1'*`2')/`3')
local V = `3' - `4' + `5'
if "$S_FLAVOR"!="Intercooled" {
if `V'>=255 {
local V = int(`3'-`4'/2 + `5')
if `V' >= 255 { local V "254" }
}
}
else {
if `V'>=2047 {
local V = int(`3'-`4'/2 + `5')
if `V' >= 255 { local V "2046" }
}
}
if "$S_NOFKEY"=="" {
mac def `7' "set maxvar `V' width `3';"
local 7 "(`7')"
}
else { local 7 }
di in gr " `7'" _col(8) in wh "set maxvar `V' width `3'" /*
*/ _col(38) in ye /*
*/ %7.0f =`O' _col(50) %6.0f =int((`3'-`4')/4) /*
*/ _col(60) %7.0f =(`O'-`6')
end
program define ChkVer
if _caller()<5 { exit }
if "$S_FLAVOR"=="Intercooled" {
di in ye "memsize" in gr " is an anachronism." _n /*
*/ "Intercooled Stata automatically repartitions memory as necessary."
exit 199
}
di in gr "The maximum number of variables and observations is fixed in Small Stata"
exit 199
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -