Skip to content

Commit

Permalink
Merge branch 'FixLoad' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
randrescastaneda committed Dec 7, 2020
2 parents 8136e85 + c612696 commit 1c5c294
Show file tree
Hide file tree
Showing 5 changed files with 445 additions and 359 deletions.
41 changes: 23 additions & 18 deletions pcn.ado
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ References:
Output:
==================================================*/


/*==================================================
0: Program set up
==================================================*/
Expand All @@ -28,12 +29,10 @@ REGions(string) ///
maindir(string) ///
type(string) ///
pause ///
vermast(string) ///
veralt(string) ///
* ///
qui ///
]
version 14
version 16

*---------- conditions
if ("`pause'" == "pause") pause on
Expand Down Expand Up @@ -73,13 +72,13 @@ qui {

* Directory path
if ("`drive'" == "") {
if ("`c(hostname)'" == "wbgmsbdat002") local drive "Q"
else local drive "P"
if ("`c(hostname)'" == "wbgmsbdat002") local drive "\\wbgmsbdat002"
else local drive "//wbntpcifs/povcalnet"
}

if ("`root'" == "") local root "01.PovcalNet/01.Vintage_control"

if ("`maindir'" == "") local maindir "`drive':/`root'"
if ("`maindir'" == "") local maindir "`drive'//`root'"

if ("`qui'" == "") {
local nq "noi"
Expand Down Expand Up @@ -118,6 +117,16 @@ qui {
}


//========================================================
// inventory
//========================================================

if regexm("`subcmd'", "^inv(e|en|ent|ento|entor|entor)") {
pcn_inventory, country(`countries') year(`years') maindir("`maindir'") /*
*/ `pause' `options'
exit
}

// ------------------------------------------------------------------------------
// Download GPWG
// -------------------------------------------------------------------------------
Expand Down Expand Up @@ -180,8 +189,7 @@ qui {
if ("`subcmd'" == "load" | "`subcmd'" == "load[ ]+gpwg") {

`nq' pcn_load, country(`countries') year(`years') type(`type') /*
*/ maindir("`maindir'") vermast(`vermast') veralt(`veralt') /*
*/ `pause' `options'
*/ maindir("`maindir'") `pause' `options'
return add
exit
}
Expand All @@ -194,8 +202,7 @@ qui {
local maindir "p:\01.PovcalNet\03.QA\02.PRIMUS\pending"

`nq' pcn_load_wrk, country(`countries') year(`years') /*
*/ maindir("`maindir'") vermast(`vermast') /*
*/ `pause' `clear' `options'
*/ maindir("`maindir'") `pause' `clear' `options'
return add
exit
}
Expand All @@ -221,8 +228,7 @@ qui {
if ("`subcmd'" == "create") {

`nq' pcn_create, countries(`countries') years(`years') type(`type') /*
*/ maindir("`maindir'") vermast(`vermast') veralt(`veralt') /*
*/ `pause' `options'
*/ maindir("`maindir'") `pause' `options'
return add
exit
}
Expand All @@ -235,8 +241,7 @@ qui {
if inlist(lower("`subcmd'"), "group", "groupdata", "gd", "groupd") {

`nq' pcn_groupdata, country(`countries') years(`years') type(`type') /*
*/ vermast(`vermast') veralt(`veralt') /*
*/ `pause' `options'
*/ `pause' `options'
return add
exit
}
Expand Down Expand Up @@ -365,14 +370,14 @@ qui {
}






} // end of qui

end

// ------------------------------------------------------------------------
// Mata functions
// ------------------------------------------------------------------------


exit

Expand Down
28 changes: 28 additions & 0 deletions pcn_functions.mata
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// MATA code to loop over primus results
// ------------------------------------------------------------------------

cap mata: mata drop pcn_*()

mata:
Expand Down Expand Up @@ -39,6 +40,33 @@ string matrix pcn_info(matrix P) {
return(P)
}
string matrix pcn_split_id(string scalar invs) {
string colvector Y
string matrix A
Y = tokens(invs)'
A = J(0,0, .z)
for (i =1; i<=rows(Y); i++) {
//printf("i=%s\n", Y[i])
if (rows(A) == 0) {
A = tokens(Y[i], "_")
}
else {
A = A \ tokens(Y[i], "_")
}
}
A = select(A, !regexm(A[1,.],"^(_|M|A)$"))
A = Y, A
return(A)
}
end

exit
Expand Down
127 changes: 66 additions & 61 deletions pcn_groupdata.ado
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ qui foreach id of local ids {
local dir `dirs'
local fileid `dir'
if regexm("`dir'", "v([0-9]+)_A") local va = "`va' " + regexs(1)
local exfile: dir "`sydir'/`dir'/Data" files "*GMD_GROUP-`cov'.dta", respect
local exfile: dir "`sydir'/`dir'/Data" files "*GMD_GD-`cov'.dta", respect
if (`"`exfile'"' == "") local fe = "`dir'" // file does not exists
}
else{
local fe = "" // file exists
local va = ""
foreach dir of local dirs {
if regexm("`dir'", "v([0-9]+)_A") local va = "`va' " + regexs(1)
local exfile: dir "`sydir'/`dir'/Data" files "*GMD_GROUP-`cov'.dta", respect
local exfile: dir "`sydir'/`dir'/Data" files "*GMD_GD-`cov'.dta", respect
if (`"`exfile'"' != "") continue
else local fe = "`dir'" // file does not exists
}
Expand All @@ -129,7 +129,7 @@ qui foreach id of local ids {
local fileid "`cc'_`yr'_`sy'_v01_M_v`va'_A_GMD"
}

local signature "`cc'_`yr'_`sy'_GMD_GROUP-`cov'"
local signature "`cc'_`yr'_`sy'_GMD_GD-`cov'"

cap datasignature confirm using /*
*/ "`sydir'/`fileid'/Data/`signature'", strict
Expand Down Expand Up @@ -158,7 +158,7 @@ qui foreach id of local ids {
local datetimeHRF: disp %tcDDmonCCYY_HH:MM:SS `datetime'
local datetimeHRF = trim("`datetimeHRF'")

char _dta[filename] `fileid'_GROUP-`cov'.dta
char _dta[filename] `fileid'_GD-`cov'.dta
char _dta[id] `fileid'
char _dta[welfaretype] `dt'
char _dta[weighttype] "PW"
Expand All @@ -169,20 +169,23 @@ qui foreach id of local ids {
char _dta[formattype] `ft'
char _dta[datetime] `datetime'
char _dta[datetimeHRF] `datetimeHRF'

char _dta[gdtype] "T`ft'"
char _dta[datatype] "`dt'"


cap mkdir "`sydir'/_vintage"
save "`sydir'/_vintage/`signature'_`datetime'.dta", replace
save "`verid'/Data/`fileid'_GROUP-`cov'.dta", replace
save "`verid'/Data/`fileid'_GD-`cov'.dta", replace

export delimited using "`verid'/Data/`fileid'_GROUP-`cov'.txt", ///
export delimited using "`verid'/Data/`fileid'_GD-`cov'.txt", ///
novarnames nolabel delimiter(tab) `replace'

export delimited using "`verid'/Data/`cc'`cov'`l2y'.T`ft'", ///
novarnames nolabel delimiter(tab) `replace'

}
else {
noi disp in y "File " in w "`fileid'_GROUP-`cov'.dta" in /*
noi disp in y "File " in w "`fileid'_GD-`cov'.dta" in /*
*/ y " is up to date."
}

Expand All @@ -193,6 +196,56 @@ qui foreach id of local ids {
restore
}

end
exit
/* End of do-file */

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

Notes:
1.
2.
3.


Version Control:


local date = c(current_date)
local time = c(current_time)
local datetime = clock("`date'`time'", "DMYhms")
disp "`datetime'"

disp %tcDDmonCCYY_HH:MM:SS `datetime'

disp %tcCCYYmonDDHHMMSS `datetime'

disp %tcCCYYNNDDHHMMSS `datetime'

local a: disp %tcCCYYNNDDHHMMSS `datetime'

local b = clock("`a'", "YMDhms")

disp %tcDDmonCCYY_HH:MM:SS `datetime'
disp %tcDDmonCCYY_HH:MM:SS `b'

local vcnumbers: dir "." files "zzz*"
local vcnumbers: subinstr local vcnumbers "zzz" "", all








local exfile: dir "../../01.Vintage_control/CHN/CHN_2016_USN/chn_2016_usn_v01_m_v01_a_pcngd/Data" files "*PCNGD-2.dta"
disp `"`exfile'"'





//------------ Check both files are in the most recent folder
qui foreach id of local ids {
local cc: word 1 of `id'
Expand All @@ -217,7 +270,7 @@ qui foreach id of local ids {

if regexm("`dir'", "v([0-9]+)_A") local va = "`va' " + regexs(1)

local exfile: dir "`sydir'/`dir'/Data" files "*GMD_GROUP-`cov'.dta", respect
local exfile: dir "`sydir'/`dir'/Data" files "*GMD_GD-`cov'.dta", respect
if (`"`exfile'"' != "") continue
else local fe = "`dir'" // file does not exists
}
Expand All @@ -234,21 +287,21 @@ qui foreach id of local ids {
mata: VC = strtoreal(tokens(`"`vcs'"')); /*
*/ st_local("mvc", strofreal(max(VC), "%15.0f"))

copy "`sydir'/vintage/`signature'_`mvc'.dta" "`sydir'/`fe'/Data/`fe'_GROUP-`cov'.dta"
copy "`sydir'/vintage/`signature'_`mvc'.dta" "`sydir'/`fe'/Data/`fe'_GD-`cov'.dta"

use "`sydir'/`fe'/Data/`fe'_GROUP-`cov'.dta", clear
use "`sydir'/`fe'/Data/`fe'_GD-`cov'.dta", clear

local datetimeHRF: disp %tcDDmonCCYY_HH:MM:SS `datetime'
local datetimeHRF = trim("`datetimeHRF'")

char _dta[filename] `fe'_GROUP-`cov'.dta
char _dta[filename] `fe'_GD-`cov'.dta
char _dta[id] `fe'
char _dta[datetime] `datetime'
char _dta[datetimeHRF] `datetimeHRF'

save, replace

export delimited using "`sydir'/`fe'/Data/`fileid'_GROUP-`cov'.txt", ///
export delimited using "`sydir'/`fe'/Data/`fileid'_GD-`cov'.txt", ///
novarnames nolabel delimiter(tab) `replace'

export delimited using "`sydir'/`fe'/Data/`cc'`cov'`l2y'.T`ft'", ///
Expand All @@ -258,51 +311,3 @@ qui foreach id of local ids {

}

end
exit
/* End of do-file */

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

Notes:
1.
2.
3.


Version Control:


local date = c(current_date)
local time = c(current_time)
local datetime = clock("`date'`time'", "DMYhms")
disp "`datetime'"

disp %tcDDmonCCYY_HH:MM:SS `datetime'

disp %tcCCYYmonDDHHMMSS `datetime'

disp %tcCCYYNNDDHHMMSS `datetime'

local a: disp %tcCCYYNNDDHHMMSS `datetime'

local b = clock("`a'", "YMDhms")

disp %tcDDmonCCYY_HH:MM:SS `datetime'
disp %tcDDmonCCYY_HH:MM:SS `b'

local vcnumbers: dir "." files "zzz*"
local vcnumbers: subinstr local vcnumbers "zzz" "", all








local exfile: dir "../../01.Vintage_control/CHN/CHN_2016_USN/chn_2016_usn_v01_m_v01_a_pcngd/Data" files "*PCNGD-2.dta"
disp `"`exfile'"'



Loading

0 comments on commit 1c5c294

Please sign in to comment.