Hi all,
I have written a command that standardizes version settings, memory settings, etc. across all users in the team I am working for. We work with projects that sometimes last almost ten years and there will be several generations of research assistants contributing to the code. As most of you already know, one should always set the version number in the beginning of do-files meant for collaboration. I want to take this concept one step further and create this command that includes more than just version number.
I know that Stata reverts all settings made inside a command after the command ends, and I both understand and fully agree with the reason why. Instead I have created a work-around for this that works, but is not as neat as I was hoping for. As of now, the only thing the command does (code attached) is that it returns a string called r(ieboil_string) with the settings separated with semi-colons. Anyone using the command must loop over that string to set the settings. See example below:
In the example below, r(ieboil_string) is on this format: "version 12.0 ; clear all ; set maxvar 32767 ; ... ; etc."
While this works, I always strive for making my commands more user friendly than this. I am afraid that this while loop is even too intimidating for some of my colleagues to start using it. I would appreciate any suggestion that anyone has regarding how to simplify the code that must follow the command in order for the settings to take place.
A specific question. The last row with subinstr() is required as gettoken includes the semi-colon in the local it stores after the first element in localname1 is stored in localnamed2. Is there any way to make gettoken to not include the parse character in either of the locals?
Finally, I tried several ways to use #delimit instead of the while loop. I tried different combinations of this, a few examples below, but none of this works. I am not familiar with the nitty-gritty details on how Stata parse code depending on the #delimit setting. Does anyone know how any of the examples below can be made to work?
Example 1.
r(ieboil_string) = "#delimit ; ; version 12.0 ; clear all ; set maxvar 32767 ; ... ; #delimit cr"
or
Example 2.
r(ieboil_string) = "version 12.0 ; clear all ; set maxvar 32767 ; ... ;"
Noe of the examples above work. Some for reasons obvious to me, but some is because I did not find documentation explaining the details of how Stata interprets each line of the code.
The command will be made available on SSC once we have tested it properly. An earlier version of this command already exist on SSC but it does not work as intended.
Thank you,
Kristoffer Bjarkefur
I have written a command that standardizes version settings, memory settings, etc. across all users in the team I am working for. We work with projects that sometimes last almost ten years and there will be several generations of research assistants contributing to the code. As most of you already know, one should always set the version number in the beginning of do-files meant for collaboration. I want to take this concept one step further and create this command that includes more than just version number.
I know that Stata reverts all settings made inside a command after the command ends, and I both understand and fully agree with the reason why. Instead I have created a work-around for this that works, but is not as neat as I was hoping for. As of now, the only thing the command does (code attached) is that it returns a string called r(ieboil_string) with the settings separated with semi-colons. Anyone using the command must loop over that string to set the settings. See example below:
In the example below, r(ieboil_string) is on this format: "version 12.0 ; clear all ; set maxvar 32767 ; ... ; etc."
Code:
ieboilstart ,v(12.0) local localname1 = r(ieboil_settings) while ("`localname1'" != "") { gettoken localname2 localname1 : localname1, parse(";")" `localname2' local localname1 = subinstr("`localname1'",";","",1) }
A specific question. The last row with subinstr() is required as gettoken includes the semi-colon in the local it stores after the first element in localname1 is stored in localnamed2. Is there any way to make gettoken to not include the parse character in either of the locals?
Finally, I tried several ways to use #delimit instead of the while loop. I tried different combinations of this, a few examples below, but none of this works. I am not familiar with the nitty-gritty details on how Stata parse code depending on the #delimit setting. Does anyone know how any of the examples below can be made to work?
Example 1.
r(ieboil_string) = "#delimit ; ; version 12.0 ; clear all ; set maxvar 32767 ; ... ; #delimit cr"
Code:
ieboilstart ,v(12.0) r(ieboil_string)
Code:
ieboilstart ,v(12.0) local return_string = r(ieboil_string) `return_string'
r(ieboil_string) = "version 12.0 ; clear all ; set maxvar 32767 ; ... ;"
Code:
ieboilstart ,v(12.0) local return_string = r(ieboil_string) #delimit ; `return_string' #delimit cr
The command will be made available on SSC once we have tested it properly. An earlier version of this command already exist on SSC but it does not work as intended.
Thank you,
Kristoffer Bjarkefur
Comment