Skip to content

Commit

Permalink
Merge pull request #281 from worldbank/ieboilstart-issue280
Browse files Browse the repository at this point in the history
[ieboilstart] - set type and set rng
  • Loading branch information
kbjarkefur authored Aug 4, 2022
2 parents ac97524 + ee7ac75 commit 5a3649e
Showing 1 changed file with 29 additions and 67 deletions.
96 changes: 29 additions & 67 deletions src/ado_files/ieboilstart.ado
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@
version 11.0

/*********************************
Check user specifed version
and apply it is valid
*********************************/

* Based on versions listed here: https://www.stata.com/support/faqs/resources/history-of-stata/
local stata_versions "11 11.0 11.1 11.2 12 12.0 12.1 13 13.0 13.1 14 14.0 14.1 14.2 15 15.0 15.1 16.0 16.1 17.0"

if `:list versionnumber in stata_versions' == 0 {

di as error "{phang}Only recent major releases are allowed. The releases currently allowed are:{break}`stata_versions'{p_end}"
di ""
error 198
Expand All @@ -33,62 +30,45 @@
*Set the version specfied in the command
version `versionnumber'



/*********************************
Check settings related to older
versions and Stata IC
*********************************/

*Test that maxvar is not set in combination when using Stata IC
if !(c(MP) == 1 | c(SE) == 1) & "`maxvar'" != "" {

di as error "{phang}In Stata IC the maximum number of variables allowed is fixed at 2,047 and maxvar() is therefore not allowed.{p_end}"
error 198
}


if "`setmem'" != "" {

if `versionnumber' >= 12 {

di as error "{phang}Option setmem() is only allowed when setting the version number to 11. Setmem() is only applicable in Stata 11 or earlier, but those versions wont be able to run this file as the version number is set to 12 or higher.{p_end}"
error 198
}


*Split the memory setting string into value and byte unit
local mem_strlen = strlen("`setmem'") -1
local mem_number = substr("`setmem'", 1 , `mem_strlen')
local mem_bytetype = substr("`setmem'", -1 , 1)


*Test that the number part is a number and a integer
cap confirm integer number `mem_number'
if _rc {

di as error "{phang}The value in setmem(`setmem') must be a number (followed by either b, k, m or g). See {help memory} for details.{p_end}"
error _rc
}

*Test that the byte type is not anything else than b, k, m or g
if !`=inlist(lower("`mem_bytetype'"), "b", "k", "m", "g")' {

di as error "{phang}The last character in setmem(`setmem') must be either b, k, m or g. See {help memory} for details.{p_end}""
error 7
}
}
else {
*Default value is 50M. This is probably too little, but
*it will safely work. And users can manually increase this
local setmem "50M"
}
*Default value is 50M. This is probably too little, but
*it will safely work. And users can manually increase this
else local setmem "50M"
/*********************************
Expand All @@ -101,7 +81,6 @@
*Setting maxvar requires a cleared memory. Therefore
*maxvar() and noclear cannot be used at the same time.
if "`maxvar'" != "" & "`clear'" != "" {
di as error "{phang}It is not possible to set allowed maximum numbers of variables without clearing the data. noclear and maxvar() can therefore not be specified at the same time{p_end}"
di ""
error 198
Expand All @@ -110,18 +89,13 @@
foreach maxlocal in maxvar matsize {
*Set locals with the max and min values fox maxvar and matsize
if "`maxlocal'" == "maxvar" {
*Stata 15 MP has a higher maximum number of maxvar
if c(stata_version) >= 15 & c(MP) == 1 {
local max 120000
}
else {
*For Stata 15 SE and MP and SE for all lower versions
local max 32767
}
if c(stata_version) >= 15 & c(MP) == 1 local max 120000
*For Stata 15 SE and MP and SE for all lower versions
else local max 32767
local min 2048
}
if "`maxlocal'" == "matsize" {
Expand All @@ -145,17 +119,12 @@
}
}
*User did not specify value, use ieboilstart's defaults:
else {
*User did not specify value, use ieboilstart's defaults:
if "`maxlocal'" == "maxvar" {
*Set maxvar to max value allowed as this is often an issue when working with large survey data
local `maxlocal' `max'
}
if "`maxlocal'" == "matsize" {
*Set to the default as the maximum is rarely requered.
local `maxlocal' 400
}
*Set maxvar to max value allowed as this is often an issue when working with large survey data
if "`maxlocal'" == "maxvar" local `maxlocal' `max'
*Set to the default as the maximum is rarely requered.
if "`maxlocal'" == "matsize" local `maxlocal' 400
}
}
Expand All @@ -168,14 +137,12 @@
**Default is that these values are set as default values so that
* these are the default values each time Stata starts.
if "`nopermanently'" == "" {
local permanently " , permanently"
local permanently_col "{col 28}, permanently"
}
else {
local permanently ""
local permanently ""
local permanently_col ""
}
/*********************************
Expand All @@ -195,7 +162,6 @@
**Setting maxvar not allowed in Stata IC.
if (c(MP) == 1 | c(SE) == 1) {
*Setting
set maxvar `maxvar' `permanently'
local setDispLocal "`setDispLocal'{break}{col 5}set maxvar {col 22}`maxvar'`permanently_col'"
Expand Down Expand Up @@ -230,37 +196,38 @@
*Set segment size to the largest value allowed by the operative system
if c(bit) == 64 {
*Setting
set segmentsize 32m `permanently'
local setDispLocal "`setDispLocal'{break}{col 5}set segmentsize {col 22}32m`permanently_col'"
}
else {
*Setting
set segmentsize 16m `permanently'
local setDispLocal "`setDispLocal'{break}{col 5}set segmentsize {col 22}16m`permanently_col'"
}
}
}
*If this dofile is generated in Stata 11 then only the old
*way of setting memory is included. This will be ignored by
*more recent versios of Stata
else {
*If this dofile is generated in Stata 11 then only the old
*way of setting memory is included. This will be ignored by
*more recent versios of Stata
*Setting
set memory `setmem'
local setDispLocal "`setDispLocal'{break}{col 5}set memory {col 22}`setmem'"
}
*********************
*Set default settings
set more off `permanently'
pause on
set varabbrev off
local setDispLocal "`setDispLocal'{break}{col 5}set more {col 22}off {col 28}, perm"
*Set simple settings
set more off `permanently'
local setDispLocal "`setDispLocal'{break}{col 5}set more {col 22}off`permanently_col'"
pause on
local setDispLocal "`setDispLocal'{break}{col 5}pause {col 22}on"
local setDispLocal "`setDispLocal'{break}{col 5}set varabbrev {col 22}off"
set varabbrev off `permanently'
local setDispLocal "`setDispLocal'{break}{col 5}set varabbrev {col 22}off`permanently_col'"
set type float `permanently'
local setDispLocal "`setDispLocal'{break}{col 5}set type {col 22}float`permanently_col'"
/*********************************
Expand Down Expand Up @@ -292,27 +259,22 @@
}
}
/*********************************
Create return value and output message
*********************************/
if "`quietly'" == "" & "`veryquietly'" == "" {
noi di ""
noi di "{phang}{err:DISCLAIMER:} Due to how settings work in Stata, this command can only attempt to harmonize settings as much as possible across users, but no guarantee can be given that all commands will always behave identically unless the exact same version and type of Stata is used, with the same releases of user-contributed commands installed.{p_end}"
noi di ""
noi di `"`setDispLocal'"'
}
if "`veryquietly'" == "" {
noi di ""
noi di "{phang}{err:IMPORTANT:} The most important setting of this command – the version – cannot be set inside the command due to technical reasons. The setting has been prepared by this command, and you only need to write \`r(version)' after this command (include the apostrophes).{p_end}"
}
}
end

0 comments on commit 5a3649e

Please sign in to comment.