|
// use, merge and append share-modules with ease: |
|
// Usage: |
|
* simply type "share" before use,merge and append commands |
|
* replace path with "module wave", e.g. "dn 9", see examples below |
|
|
|
// Setup: |
|
* copy-paste the share-programme in the beginning of your do-file (or in profile.do so that the programme is loaded automatically when you launch stata) |
|
* check the lines with "NB!" below. You will need to make some minor changes to the code in order to update the directories, release numbers etc. |
|
|
|
//Credit: |
|
* Daniel Klein https://www.statalist.org/forums/member/103-daniel-klein |
|
* For more info, please visit the original post https://www.statalist.org/forums/forum/general-stata-discussion/general/1744123-simple-user-defined-function-program-with-custom-input-and-output |
|
|
|
cap nois program drop share |
|
program share |
|
|
|
version 18 |
|
|
|
syntax anything [ using/ ] [ if ] [ in ] [ , * ] |
|
|
|
local mydirectory ="C:\D\SHARE\public" //"C:/PATH_TO_YOUR_DIRECTORY" // NB! update with your path (every wave will need to be in its own folder) |
|
if ("`using'" == "") { |
|
|
|
/* |
|
<module> and <wave> are part of <anything> |
|
|
|
More specifically, we assume that <anything> is |
|
|
|
<command> "<module> <wave>" |
|
|
|
as in, e.g., |
|
|
|
use "<module> <wave>" |
|
|
|
(double quotes optional) |
|
*/ |
|
|
|
gettoken command anything : anything |
|
gettoken module anything : anything |
|
gettoken wave anything : anything |
|
|
|
if (`"`anything'"' != "") error 198 |
|
|
|
local anything `command' |
|
|
|
local using `module' `wave' |
|
|
|
} |
|
else local the_word_using "using" |
|
|
|
gettoken module wave_void : using |
|
gettoken wave void : wave_void |
|
|
|
if ("`void'" != "") error 198 |
|
|
|
capture local wave =string(`wave') |
|
*confirm integer number `wave' |
|
*di "test1" |
|
// NB! Make sure that releases and folder names match with yours (do not change any names after downloading it from the data portal) |
|
local release = cond("`wave'"=="9", "rel0", "rel8-0-0") // update release in here |
|
local using "`mydirectory'/sharew`wave'_`release'_ALL_datasets_stata" |
|
local using "`using'/sharew`wave'_`release'_`module'.dta" |
|
|
|
display "Module: `module' | Wave: `wave'" |
|
display "File path: `using'" |
|
di "`using'" |
|
`anything' `the_word_using' "`using'" `if' `in' , `options' |
|
|
|
end |
|
|
|
share use "dn 6", clear |
|
share merge 1:1 mergeid using "gv_health 8", keepusing(maxgrip) |
|
share merge 1:1 mergeid using "ca 9ca", keepusing(cah006) nogenerate |
|
share merge 1:1 mergeid using "br 9", keepusing(br001_) nogenerate |
|
share append using "dn 7" |