From c1489746b240a8cc6671ad669d973a4147cbedd6 Mon Sep 17 00:00:00 2001 From: "R.Andres Castaneda" Date: Thu, 19 Nov 2020 13:47:13 -0500 Subject: [PATCH] create package --- p/Primus32.dll => Primus32.dll | Bin p/Primus64.dll => Primus64.dll | Bin make.do | 15 + p/primus.ado => primus.ado | 112 +- primus.pkg | 24 + p/primus.sthlp => primus.sthlp | 276 +- p/primus_action.ado => primus_action.ado | 190 +- p/primus_action.sthlp => primus_action.sthlp | 106 +- p/primus_check.ado => primus_check.ado | 234 +- p/primus_download.ado => primus_download.ado | 126 +- ...us_download.sthlp => primus_download.sthlp | 78 +- p/primus_message.ado => primus_message.ado | 78 +- p/primus_query.ado => primus_query.ado | 206 +- p/primus_query.sthlp => primus_query.sthlp | 116 +- p/primus_up.ado => primus_up.ado | 2102 +++++----- p/primus_upload.ado => primus_upload.ado | 3480 ++++++++--------- p/primus_upload.sthlp => primus_upload.sthlp | 694 ++-- p/primus_vintage.ado => primus_vintage.ado | 298 +- stata.toc | 9 + 19 files changed, 4096 insertions(+), 4048 deletions(-) rename p/Primus32.dll => Primus32.dll (100%) rename p/Primus64.dll => Primus64.dll (100%) create mode 100644 make.do rename p/primus.ado => primus.ado (96%) create mode 100644 primus.pkg rename p/primus.sthlp => primus.sthlp (97%) rename p/primus_action.ado => primus_action.ado (97%) rename p/primus_action.sthlp => primus_action.sthlp (97%) rename p/primus_check.ado => primus_check.ado (95%) rename p/primus_download.ado => primus_download.ado (96%) rename p/primus_download.sthlp => primus_download.sthlp (95%) rename p/primus_message.ado => primus_message.ado (98%) rename p/primus_query.ado => primus_query.ado (97%) rename p/primus_query.sthlp => primus_query.sthlp (97%) rename p/primus_up.ado => primus_up.ado (97%) rename p/primus_upload.ado => primus_upload.ado (97%) rename p/primus_upload.sthlp => primus_upload.sthlp (97%) rename p/primus_vintage.ado => primus_vintage.ado (96%) create mode 100644 stata.toc diff --git a/p/Primus32.dll b/Primus32.dll similarity index 100% rename from p/Primus32.dll rename to Primus32.dll diff --git a/p/Primus64.dll b/Primus64.dll similarity index 100% rename from p/Primus64.dll rename to Primus64.dll diff --git a/make.do b/make.do new file mode 100644 index 0000000..e571aaf --- /dev/null +++ b/make.do @@ -0,0 +1,15 @@ +// the 'make.do' file is automatically created by 'github' package. +// execute the code below to generate the package installation files. +// DO NOT FORGET to update the version of the package, if changed! +// for more information visit http://github.com/haghish/github + +make primus, toc pkg version(0.0.0.9000) /// + license("MIT") /// + author("R.Andres Castaneda") /// + affiliation("The World Bank") /// + email("acastanedaa@worldbank.org") /// + url("https://github.com/worldbank/primus") /// + title("PRIMUS") /// + description("The Primus ado files for Stata in this GitHub repo are a critical component of this process. These allow for data sharing and file upload service that ensures that estimations are based on identical source data.") /// + install("primus.ado;primus.sthlp;primus_action.ado;primus_action.sthlp;primus_check.ado;primus_download.ado;primus_download.sthlp;primus_message.ado;primus_query.ado;primus_query.sthlp;primus_up.ado;primus_upload.ado;primus_upload.sthlp;primus_vintage.ado;Primus32.dll;Primus64.dll") /// + iancillary("") diff --git a/p/primus.ado b/primus.ado similarity index 96% rename from p/primus.ado rename to primus.ado index 1eed0d9..6105a82 100644 --- a/p/primus.ado +++ b/primus.ado @@ -1,56 +1,56 @@ -*! version 0.0.1 12Feb2018 -*! Copyright (C) World Bank 2017-18 - -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. - -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. - -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . - -cap program drop primus -program primus, rclass - version 11.0 - local version : di "version " string(_caller()) ":" - set prefix primus - gettoken subcmd 0 : 0, parse(" :,=[]()+-") - local l = strlen("`subcmd'") - - if ("`subcmd'"=="upload") { //upload relelated tasks - primus_upload `0' - } - else if ("`subcmd'"=="query") { //query PRIMUS data - primus_query `0' - } - else if ("`subcmd'"=="download") { - primus_download `0' - } - else if ("`subcmd'"=="action") { - primus_action `0' - } - else { //none of the above - if ("`subcmd'"=="") { - di as smcl as err "syntax error" - di as smcl as err "{p 4 4 2}" - di as smcl as err "{bf:primus} must be followed by a subcommand." - di as smcl as err "You might type {bf:primus upload}, or {bf:primus query}, or {bf:primus action}, etc." - di as smcl as err "{p_end}" - exit 198 - } - capture which primus_cmd_`subcmd' - if (_rc) { - if (_rc==1) exit 1 - di as smcl as err "unrecognized subcommand: {bf:primus `subcmd'}" - exit 199 - /*NOTREACHED*/ - } - `version' primus_cmd_`subcmd' `0' - } - return add -end +*! version 0.0.1 12Feb2018 +*! Copyright (C) World Bank 2017-18 + +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . + +cap program drop primus +program primus, rclass + version 11.0 + local version : di "version " string(_caller()) ":" + set prefix primus + gettoken subcmd 0 : 0, parse(" :,=[]()+-") + local l = strlen("`subcmd'") + + if ("`subcmd'"=="upload") { //upload relelated tasks + primus_upload `0' + } + else if ("`subcmd'"=="query") { //query PRIMUS data + primus_query `0' + } + else if ("`subcmd'"=="download") { + primus_download `0' + } + else if ("`subcmd'"=="action") { + primus_action `0' + } + else { //none of the above + if ("`subcmd'"=="") { + di as smcl as err "syntax error" + di as smcl as err "{p 4 4 2}" + di as smcl as err "{bf:primus} must be followed by a subcommand." + di as smcl as err "You might type {bf:primus upload}, or {bf:primus query}, or {bf:primus action}, etc." + di as smcl as err "{p_end}" + exit 198 + } + capture which primus_cmd_`subcmd' + if (_rc) { + if (_rc==1) exit 1 + di as smcl as err "unrecognized subcommand: {bf:primus `subcmd'}" + exit 199 + /*NOTREACHED*/ + } + `version' primus_cmd_`subcmd' `0' + } + return add +end diff --git a/primus.pkg b/primus.pkg new file mode 100644 index 0000000..f48940a --- /dev/null +++ b/primus.pkg @@ -0,0 +1,24 @@ +v 0.0.0.9000 +d 'PRIMUS': PRIMUS +d +d The Primus ado files for Stata in this GitHub repo are a critical component of this process. These allow for data sharing and file upload service that ensures that estimations are based on identical source data. +d +d Distribution-Date: 20201119 +d License: MIT +d +F Primus32.dll +F Primus64.dll +F primus.ado +F primus.sthlp +F primus_action.ado +F primus_action.sthlp +F primus_check.ado +F primus_download.ado +F primus_download.sthlp +F primus_message.ado +F primus_query.ado +F primus_query.sthlp +F primus_up.ado +F primus_upload.ado +F primus_upload.sthlp +F primus_vintage.ado diff --git a/p/primus.sthlp b/primus.sthlp similarity index 97% rename from p/primus.sthlp rename to primus.sthlp index 0869bf5..27d0bbf 100644 --- a/p/primus.sthlp +++ b/primus.sthlp @@ -1,138 +1,138 @@ -{smcl} -{* *! version 1.0.0 11nov2017}{...} -{viewerdialog primus "dialog primus"}{...} -{vieweralsosee "[PRIMUS] intro" "mansection PRIMUS intro"}{...} -{vieweralsosee "" "--"}{...} -{vieweralsosee "[PRIMUS] Glossary" "help primus_glossary"}{...} -{vieweralsosee "[PRIMUS] intro substantive" "help primus_intro_substantive"}{...} -{vieweralsosee "[PRIMUS] styles" "help primus_styles"}{...} -{vieweralsosee "[PRIMUS] workflow" "help primus_workflow"}{...} -{viewerjumpto "Description" "primus##description"}{...} -{viewerjumpto "Remarks" "primus##remarks"}{...} -{viewerjumpto "Acknowledgments" "primus##ack"}{...} -{title:Title} - -{hline} -help for {cmd:primus} {right:World Bank/Poverty and Equity GP - GSG1} -{hline} - -{p2colset 5 19 21 2}{...} -{p2col :{manlink PRIMUS intro} {hline 2}}Introduction to primus - PRIMUS packages{p_end} -{p2colreset}{...} - -{p 8 9 9} -{it:[Suggestion: Read} -{bf:{help primus_intro_substantive:[PRIMUS] intro substantive}} -{it:first.]} - - -{marker description}{...} -{title:Description} - - {c TLC}{hline 62}{c TRC} - {c |} The {cmd:primus} suite of commands deals approval of poverty {col 68}{c |} - {c |} indicators based on the microdata submitted to PRIMUS. {col 68}{c |} - {c |} Currently, there are three approval roles in the system. {col 68}{c |} - {c |} They are Regional team, DECDG, and Povcalnet {col 68}{c |} - {c |}{col 68}{c |} - {c |} To become familiar with {cmd:primus} as quickly as possible,{col 68}{c |} - {c |} you can do the following{col 68}{c |} - {c |}{col 68}{c |} - {c |} 1. See {it:{help sae##example:A simple example}} under {...} -{bf:{help sae##remarks:Remarks}} below.{col 68}{c |} - {c |}{col 68}{c |} - {c |} 2. To upload the data into PRIMUS, see{col 68}{c |} - {c |} {bf:{help primus_upload:[PRIMUS] primus upload}}{col 68}{c |} - {c |}{col 68}{c |} - {c |} 3. To query the status of PRIMUS transaction, see{col 68}{c |} - {c |} {bf:{help primus_query:[PRIMUS] primus query}}{col 68}{c |} - {c |}{col 68}{c |} - {c |} 4. To download the indicators submitted into PRIMUS, see{col 68}{c |} - {c |} {bf:{help primus_download:[PRIMUS] primus download}}{col 68}{c |} - {c |}{col 68}{c |} - {c |} 5. To act (confirm, reject, or approved) transactions in {col 68}{c |} - {c |} in PRIMUS, see{col 68}{c |} - {c |} {bf:{help primus_action:[PRIMUS] primus action}}{col 68}{c |} - {c BLC}{hline 62}{c BRC} - - -{marker remarks}{...} -{title:Remarks} - -{p 4 4 2} -Remarks are presented under the following headings: - - {help primus##example:A simple example} - - -{marker example}{...} -{title:{it:A simple example}} - -{pstd} -Step 1. We are about to upload GEO 2015 data into PRIMUS: - -{phang}{cmd:. primus, countrycode(GEO) year(2015) welfare(gallT) welfaretype(CONS) welfshprosperity(gallT2) welfshprtype(CONS) weight(weight1) weighttype(FW) hsize(hhsize) hhid(hhid1) cpi(cpi2011) cpiperiod(year) ppp(icp2011) welfaredef(gallT) urban(urb) survey("HIS") vermast("`vermast_p'") harmonization(ECAPOV) veralt("`veralt_p'") othervariables(quarter gallT2) icpbase(2011) save13 module(GPWG) output(C:Temp\test.xlsx)} {p_end} - -{pstd} -Step 2. We then query the status of the PRIMUS transactions with the overall status as PENDING, either for the ECA region as a whole or by the transaction ID reported above. - -{phang}{cmd:. primus query, overallstatus(PENDING)} {p_end} -{pstd} - -{pstd} -Step 3. We then download the indicators submitted to PRIMUS based on the data you sent in Step 1. - -{phang}{cmd:. primus download, tranxid(TRN-000008971-ECA-GEO-U0FHW)} {p_end} - -{pstd} Step 4. After you check and confirm the poverty and inequality numbers in PRIMUS system, you can act on it with ONE of the follow choices: - -{phang}{cmd:. primus action, tranxid(TRN-000008971-ECA-GEO-U0FHW) indexid(1) decision(CONFIRMED)} {p_end} -{pstd} 4a. User put a "CONFIRMED" action on the transaction, this is the first step of the PRIMUS workflow. After the confirmation of the Uploader, the transaction will be available for the approvers to act upon. - -{phang}{cmd:. primus action, tranxid(TRN-000008971-ECA-GEO-U0FHW) decision(approved)} {p_end} -{pstd} 4b. User put a "APPROVED" action on the transaction. This is only possible when Uploader had confirmed or no one from the approver's role have act upon the transaction. Transaction cannot be approved/rejected more than one or change the action after it goes through. - -{phang}{cmd:. primus action, tranxid(TRN-000008971-ECA-GEO-U0FHW) indexid(1) decision(rejected) comments(The numbers are not correct due to chanegs in welfare)} {p_end} -{pstd} 4c. User put a "REJECTED" action on the transaction. In this case, it could be the rejection from the uploader role or from the approver role, depending on the stage of the transaction ID. Comments are required for any rejections. - -{marker order}{...} -{title:{it:Suggested reading order}} - -{p 4 4 2} -The order of suggested reading of this manual is - - {bf:[PRIMUS] intro} - {bf:{help primus_upload:[PRIMUS] primus upload}} - {bf:{help primus_query:[PRIMUS] primus query}} - {bf:{help primus_download:[PRIMUS] primus download}} - {bf:{help primus_action:[PRIMUS] primus action}} - -{p 4 4 2} -Programmers will want to see -{bf:{help primus_technical:[PRIMUS] technical}}. - -{marker references}{...} -{title:References} -{marker R2004}{...} -{p 4 8 2} -Authors. 2018. - {browse "http://www.worldbank.org":PRIMUS workflow.} - {it:Working Paper} 1: 1-8. - -{p 4 4 2} List of papers here. -{p_end} - -{title:Authors} - {p 4 4 2}World Bank{p_end} - -{title:Thanks for citing {cmd:primus} as follows} - -{p 4 4 2}{cmd: primus} is a user-written program that is freely distributed to the research community. {p_end} - -{p 4 4 2}Please use the following citation:{p_end} -{p 4 4 2}World Bank. (2017). “{cmd:primus}: Stata module to ...”. World Bank. -{p_end} - -{title:Acknowledgements} - {p 4 4 2}We would like to thank .... - All errors and ommissions are exclusively our responsibility.{p_end} +{smcl} +{* *! version 1.0.0 11nov2017}{...} +{viewerdialog primus "dialog primus"}{...} +{vieweralsosee "[PRIMUS] intro" "mansection PRIMUS intro"}{...} +{vieweralsosee "" "--"}{...} +{vieweralsosee "[PRIMUS] Glossary" "help primus_glossary"}{...} +{vieweralsosee "[PRIMUS] intro substantive" "help primus_intro_substantive"}{...} +{vieweralsosee "[PRIMUS] styles" "help primus_styles"}{...} +{vieweralsosee "[PRIMUS] workflow" "help primus_workflow"}{...} +{viewerjumpto "Description" "primus##description"}{...} +{viewerjumpto "Remarks" "primus##remarks"}{...} +{viewerjumpto "Acknowledgments" "primus##ack"}{...} +{title:Title} + +{hline} +help for {cmd:primus} {right:World Bank/Poverty and Equity GP - GSG1} +{hline} + +{p2colset 5 19 21 2}{...} +{p2col :{manlink PRIMUS intro} {hline 2}}Introduction to primus - PRIMUS packages{p_end} +{p2colreset}{...} + +{p 8 9 9} +{it:[Suggestion: Read} +{bf:{help primus_intro_substantive:[PRIMUS] intro substantive}} +{it:first.]} + + +{marker description}{...} +{title:Description} + + {c TLC}{hline 62}{c TRC} + {c |} The {cmd:primus} suite of commands deals approval of poverty {col 68}{c |} + {c |} indicators based on the microdata submitted to PRIMUS. {col 68}{c |} + {c |} Currently, there are three approval roles in the system. {col 68}{c |} + {c |} They are Regional team, DECDG, and Povcalnet {col 68}{c |} + {c |}{col 68}{c |} + {c |} To become familiar with {cmd:primus} as quickly as possible,{col 68}{c |} + {c |} you can do the following{col 68}{c |} + {c |}{col 68}{c |} + {c |} 1. See {it:{help sae##example:A simple example}} under {...} +{bf:{help sae##remarks:Remarks}} below.{col 68}{c |} + {c |}{col 68}{c |} + {c |} 2. To upload the data into PRIMUS, see{col 68}{c |} + {c |} {bf:{help primus_upload:[PRIMUS] primus upload}}{col 68}{c |} + {c |}{col 68}{c |} + {c |} 3. To query the status of PRIMUS transaction, see{col 68}{c |} + {c |} {bf:{help primus_query:[PRIMUS] primus query}}{col 68}{c |} + {c |}{col 68}{c |} + {c |} 4. To download the indicators submitted into PRIMUS, see{col 68}{c |} + {c |} {bf:{help primus_download:[PRIMUS] primus download}}{col 68}{c |} + {c |}{col 68}{c |} + {c |} 5. To act (confirm, reject, or approved) transactions in {col 68}{c |} + {c |} in PRIMUS, see{col 68}{c |} + {c |} {bf:{help primus_action:[PRIMUS] primus action}}{col 68}{c |} + {c BLC}{hline 62}{c BRC} + + +{marker remarks}{...} +{title:Remarks} + +{p 4 4 2} +Remarks are presented under the following headings: + + {help primus##example:A simple example} + + +{marker example}{...} +{title:{it:A simple example}} + +{pstd} +Step 1. We are about to upload GEO 2015 data into PRIMUS: + +{phang}{cmd:. primus, countrycode(GEO) year(2015) welfare(gallT) welfaretype(CONS) welfshprosperity(gallT2) welfshprtype(CONS) weight(weight1) weighttype(FW) hsize(hhsize) hhid(hhid1) cpi(cpi2011) cpiperiod(year) ppp(icp2011) welfaredef(gallT) urban(urb) survey("HIS") vermast("`vermast_p'") harmonization(ECAPOV) veralt("`veralt_p'") othervariables(quarter gallT2) icpbase(2011) save13 module(GPWG) output(C:Temp\test.xlsx)} {p_end} + +{pstd} +Step 2. We then query the status of the PRIMUS transactions with the overall status as PENDING, either for the ECA region as a whole or by the transaction ID reported above. + +{phang}{cmd:. primus query, overallstatus(PENDING)} {p_end} +{pstd} + +{pstd} +Step 3. We then download the indicators submitted to PRIMUS based on the data you sent in Step 1. + +{phang}{cmd:. primus download, tranxid(TRN-000008971-ECA-GEO-U0FHW)} {p_end} + +{pstd} Step 4. After you check and confirm the poverty and inequality numbers in PRIMUS system, you can act on it with ONE of the follow choices: + +{phang}{cmd:. primus action, tranxid(TRN-000008971-ECA-GEO-U0FHW) indexid(1) decision(CONFIRMED)} {p_end} +{pstd} 4a. User put a "CONFIRMED" action on the transaction, this is the first step of the PRIMUS workflow. After the confirmation of the Uploader, the transaction will be available for the approvers to act upon. + +{phang}{cmd:. primus action, tranxid(TRN-000008971-ECA-GEO-U0FHW) decision(approved)} {p_end} +{pstd} 4b. User put a "APPROVED" action on the transaction. This is only possible when Uploader had confirmed or no one from the approver's role have act upon the transaction. Transaction cannot be approved/rejected more than one or change the action after it goes through. + +{phang}{cmd:. primus action, tranxid(TRN-000008971-ECA-GEO-U0FHW) indexid(1) decision(rejected) comments(The numbers are not correct due to chanegs in welfare)} {p_end} +{pstd} 4c. User put a "REJECTED" action on the transaction. In this case, it could be the rejection from the uploader role or from the approver role, depending on the stage of the transaction ID. Comments are required for any rejections. + +{marker order}{...} +{title:{it:Suggested reading order}} + +{p 4 4 2} +The order of suggested reading of this manual is + + {bf:[PRIMUS] intro} + {bf:{help primus_upload:[PRIMUS] primus upload}} + {bf:{help primus_query:[PRIMUS] primus query}} + {bf:{help primus_download:[PRIMUS] primus download}} + {bf:{help primus_action:[PRIMUS] primus action}} + +{p 4 4 2} +Programmers will want to see +{bf:{help primus_technical:[PRIMUS] technical}}. + +{marker references}{...} +{title:References} +{marker R2004}{...} +{p 4 8 2} +Authors. 2018. + {browse "http://www.worldbank.org":PRIMUS workflow.} + {it:Working Paper} 1: 1-8. + +{p 4 4 2} List of papers here. +{p_end} + +{title:Authors} + {p 4 4 2}World Bank{p_end} + +{title:Thanks for citing {cmd:primus} as follows} + +{p 4 4 2}{cmd: primus} is a user-written program that is freely distributed to the research community. {p_end} + +{p 4 4 2}Please use the following citation:{p_end} +{p 4 4 2}World Bank. (2017). “{cmd:primus}: Stata module to ...”. World Bank. +{p_end} + +{title:Acknowledgements} + {p 4 4 2}We would like to thank .... + All errors and ommissions are exclusively our responsibility.{p_end} diff --git a/p/primus_action.ado b/primus_action.ado similarity index 97% rename from p/primus_action.ado rename to primus_action.ado index 7816432..f39bc08 100644 --- a/p/primus_action.ado +++ b/primus_action.ado @@ -1,95 +1,95 @@ -*! version 0.0.1 23Feb2018 -*! Copyright (C) World Bank 2017-18 - -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. - -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. - -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . - -capture program define _primus, plugin using("Primus`=cond(strpos(`"`=c(machine_type)'"',"64"),64,32)'.dll") -cap program drop primus_action -program primus_action, rclass - version 11.0 - syntax [anything] [, /// - TRANxid(string) INDEXid(string) /// - Decision(string) Comments(string) ] - - global errcodep 0 - local opt 3 - local server 3 - global errcodep = 0 - tempfile decisionout - if "`tranxid'"~="" { - local tranxid `=upper("`tranxid'")' - local decision `=upper("`decision'")' - if `= wordcount("`tranxid'")' > 1 { - noi dis as error "There should be ONLY one transaction ID" - global errcodep = 1 - } - else { //tranxid - if `= wordcount("`decision'")' > 1 { - noi dis as error "There should be ONLY one decision" - global errcodep = 1 - error 198 - } - else { //decision - if (!inlist("`decision'","APPROVED", "REJECTED", "CONFIRMED")) { - noi disp as error "The input on the decision() is not correct. Available options are: APPROVE, REJECT." - error 198 - } - else { - if "`decision'"=="REJECTED" & "`comments'"=="" { - noi dis as error "You must have comments when rejecting a transaction" - global errcodep = 1 - error 198 - } - if ("`decision'"=="APPROVED" | "`decision'"=="CONFIRMED") & "`comments'"=="" local comments `=c(username)' - - //API - qui plugin call _primus , "`opt'" "TransactionId=`tranxid'&Decision=`decision'&Comments=`comments'&IndexID=`indexid'" "`decisionout'" "`server'" - if `primusRC'==0 { - cap insheet using "`decisionout'", clear - if _rc==0 { - if _N>0 { - noi dis as text in red "{p 4 4 2}`=action_status[1]'{p_end}" - if `=error_code[1]'~=3 { - clear - error 1 - } - else clear - } - else { - noi dis as error "Fail to put action (`decision') for the transaction ID `tranxid'!" - global errcodep = 1 - error 198 - } - } //insheet - else { - noi dis as error "Fail to put action (`decision') for the transaction ID `tranxid'!" - global errcodep = 1 - error 198 - } - } //plugin - else { - noi dis as error "Fail to put action (`decision') for the transaction ID `tranxid'!" - global errcodep = 1 - error 198 - } - } - } //decision - } //xid - } - else { - noi dis as error "There should be one transaction ID" - global errcodep = 1 - error 198 - } -end +*! version 0.0.1 23Feb2018 +*! Copyright (C) World Bank 2017-18 + +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . + +capture program define _primus, plugin using("Primus`=cond(strpos(`"`=c(machine_type)'"',"64"),64,32)'.dll") +cap program drop primus_action +program primus_action, rclass + version 11.0 + syntax [anything] [, /// + TRANxid(string) INDEXid(string) /// + Decision(string) Comments(string) ] + + global errcodep 0 + local opt 3 + local server 3 + global errcodep = 0 + tempfile decisionout + if "`tranxid'"~="" { + local tranxid `=upper("`tranxid'")' + local decision `=upper("`decision'")' + if `= wordcount("`tranxid'")' > 1 { + noi dis as error "There should be ONLY one transaction ID" + global errcodep = 1 + } + else { //tranxid + if `= wordcount("`decision'")' > 1 { + noi dis as error "There should be ONLY one decision" + global errcodep = 1 + error 198 + } + else { //decision + if (!inlist("`decision'","APPROVED", "REJECTED", "CONFIRMED")) { + noi disp as error "The input on the decision() is not correct. Available options are: APPROVE, REJECT." + error 198 + } + else { + if "`decision'"=="REJECTED" & "`comments'"=="" { + noi dis as error "You must have comments when rejecting a transaction" + global errcodep = 1 + error 198 + } + if ("`decision'"=="APPROVED" | "`decision'"=="CONFIRMED") & "`comments'"=="" local comments `=c(username)' + + //API + qui plugin call _primus , "`opt'" "TransactionId=`tranxid'&Decision=`decision'&Comments=`comments'&IndexID=`indexid'" "`decisionout'" "`server'" + if `primusRC'==0 { + cap insheet using "`decisionout'", clear + if _rc==0 { + if _N>0 { + noi dis as text in red "{p 4 4 2}`=action_status[1]'{p_end}" + if `=error_code[1]'~=3 { + clear + error 1 + } + else clear + } + else { + noi dis as error "Fail to put action (`decision') for the transaction ID `tranxid'!" + global errcodep = 1 + error 198 + } + } //insheet + else { + noi dis as error "Fail to put action (`decision') for the transaction ID `tranxid'!" + global errcodep = 1 + error 198 + } + } //plugin + else { + noi dis as error "Fail to put action (`decision') for the transaction ID `tranxid'!" + global errcodep = 1 + error 198 + } + } + } //decision + } //xid + } + else { + noi dis as error "There should be one transaction ID" + global errcodep = 1 + error 198 + } +end diff --git a/p/primus_action.sthlp b/primus_action.sthlp similarity index 97% rename from p/primus_action.sthlp rename to primus_action.sthlp index 582136a..833bc8d 100644 --- a/p/primus_action.sthlp +++ b/primus_action.sthlp @@ -1,53 +1,53 @@ -{smcl} -{* *! version 0.0.1 19Jan2018}{...} -{cmd:help primus_action} -{hline} - -{title:Title} - -{p2colset 5 24 26 2}{...} -{p2col :}{cmd:primus action} {hline 1} Put an action on PRIMUS transactions -{p2colreset}{...} - -{marker syntax}{...} -{title:Syntax} - -{p 8 17 2} -{cmdab:primus action} -{cmd:,[} -{opt tran:xid(string)} {opt d:ecision(string)} {opt c:omments(string)} {opt index:id(string)}] - -{synoptline} -{p2colreset}{...} - -{marker description}{...} -{title:Description} - -{pstd} -{cmd:primus action} Put an action on PRIMUS transaction based on the user's role in the PRIMUS system. - -{marker options}{...} -{title:Options} - -{dlgtab:Optional} - -{synopt:{opth tran:xid(string)}} Transaction ID, accept ONLY one transaction ID{p_end} -{synopt:{opth d:ecision(string)}} Decision to be act on the Transaction ID. Uploader can either "CONFIRMED" or "REJECTED"; and Approvers can "APPROVED" or "REJECTED"{p_end} -{synopt:{opth c:omments(string)}} Comments must be for REJECTED. For CONFIRMED or APPROVED, system can use username as the comments.{p_end} -{synopt:{opth index:id(string)}} It is the calculation index provided by the primus download for each transaction. It indicates the choices based on the combination of several input such as Welfare Set, Method, PPP value, CPI value, Group as indicated in the PRIMUS view. The default value is 1 if it is missing.{p_end} - -{marker examples}{...} -{title:Examples} - -{phang}{cmd:. primus action, tranxid(TRN-000252482-ECA-MDA-W8CKO) indexid(1) decision(CONFIRMED)} {p_end} -{pstd} -User put an "CONFIRMED" action on the transaction, this is the first step of the PRIMUS workflow. After the confirmation of the Uploader, the transaction will be available for the approvers to act upon. - -{phang}{cmd:. primus action, tranxid(TRN-000252482-SSA-COM-6VJC1) decision(approved)} {p_end} -{pstd} -User put an "APPROVED" action on the transaction. This is only possible when Uploader had confirmed or no one from the approver's role have act upon the transaction. Transaction cannot be approved/rejected more than one or change the action after it goes through. - -{phang}{cmd:. primus action, tranxid(TRN-000252482-ECA-ARM-S7F8U) indexid(1) decision(rejected) comments(esyashdhs0 jjjkj)} {p_end} -{pstd} -User put an "REJECTED" action on the transaction. In this case, it could be the rejection from the uploader role or from the approver role, depending on the stage of the transaction ID. Comments are required for any rejections. - +{smcl} +{* *! version 0.0.1 19Jan2018}{...} +{cmd:help primus_action} +{hline} + +{title:Title} + +{p2colset 5 24 26 2}{...} +{p2col :}{cmd:primus action} {hline 1} Put an action on PRIMUS transactions +{p2colreset}{...} + +{marker syntax}{...} +{title:Syntax} + +{p 8 17 2} +{cmdab:primus action} +{cmd:,[} +{opt tran:xid(string)} {opt d:ecision(string)} {opt c:omments(string)} {opt index:id(string)}] + +{synoptline} +{p2colreset}{...} + +{marker description}{...} +{title:Description} + +{pstd} +{cmd:primus action} Put an action on PRIMUS transaction based on the user's role in the PRIMUS system. + +{marker options}{...} +{title:Options} + +{dlgtab:Optional} + +{synopt:{opth tran:xid(string)}} Transaction ID, accept ONLY one transaction ID{p_end} +{synopt:{opth d:ecision(string)}} Decision to be act on the Transaction ID. Uploader can either "CONFIRMED" or "REJECTED"; and Approvers can "APPROVED" or "REJECTED"{p_end} +{synopt:{opth c:omments(string)}} Comments must be for REJECTED. For CONFIRMED or APPROVED, system can use username as the comments.{p_end} +{synopt:{opth index:id(string)}} It is the calculation index provided by the primus download for each transaction. It indicates the choices based on the combination of several input such as Welfare Set, Method, PPP value, CPI value, Group as indicated in the PRIMUS view. The default value is 1 if it is missing.{p_end} + +{marker examples}{...} +{title:Examples} + +{phang}{cmd:. primus action, tranxid(TRN-000252482-ECA-MDA-W8CKO) indexid(1) decision(CONFIRMED)} {p_end} +{pstd} +User put an "CONFIRMED" action on the transaction, this is the first step of the PRIMUS workflow. After the confirmation of the Uploader, the transaction will be available for the approvers to act upon. + +{phang}{cmd:. primus action, tranxid(TRN-000252482-SSA-COM-6VJC1) decision(approved)} {p_end} +{pstd} +User put an "APPROVED" action on the transaction. This is only possible when Uploader had confirmed or no one from the approver's role have act upon the transaction. Transaction cannot be approved/rejected more than one or change the action after it goes through. + +{phang}{cmd:. primus action, tranxid(TRN-000252482-ECA-ARM-S7F8U) indexid(1) decision(rejected) comments(esyashdhs0 jjjkj)} {p_end} +{pstd} +User put an "REJECTED" action on the transaction. In this case, it could be the rejection from the uploader role or from the approver role, depending on the stage of the transaction ID. Comments are required for any rejections. + diff --git a/p/primus_check.ado b/primus_check.ado similarity index 95% rename from p/primus_check.ado rename to primus_check.ado index 43720a9..202bf1e 100644 --- a/p/primus_check.ado +++ b/primus_check.ado @@ -1,117 +1,117 @@ -cap program drop primus_check -program define primus_check, rclass - - version 11.0 - - syntax, country(string) verm(string) vera(string) year(numlist int max=1 >1900) /// - module(string) - - local toup country svy module - - foreach x of local toup{ - if ("``x''"!="") local `x' =trim(upper("``x''")) - } - - foreach x of varlist *{ - local tocheck `tocheck' `x' - } - - cap isid hhid - local hhlev =_rc==0 - if (`hhlev'!=1){ - cap isid hhid pid - if (_rc==0){ - sort hhid pid - } - else{ - dis as error "Data is not at hh or individual level" - error 2343 - exit - } - } - else sort hhid - - tempfile current - save `current' - - cap datalibweb, country(`country') year(`year') verm(`verm') vera(`vera') module(`module') type(gmd) clear nocpi - local nogo = _rc - cap drop cpi* - cap drop icp* - cap drop ppp* - cap drop datalevel - cap replace countrycode=upper(countrycode) - - if (`nogo'==0){ - cap rename weight weight_h - - qui: count - local NN=r(N) - - foreach x of varlist *{ - qui: count if missing(`x') - local NNn=r(N) - if (`NN'!=`NNn') local tocheckn `tocheckn' `x' - } - cap isid hhid - local hhlev =_rc==0 - if (`hhlev'!=1){ - cap isid hhid pid - local indivlev = _rc==0 - if (`indivlev'==1){ - sort hhid pid - } - else{ - dis as error "Data is not at hh or individual level" - error 2343 - exit - } - } - else{ - sort hhid - } - - //Check if there are vars in tocheckn not in tocheck - local notin: list tocheckn - tocheck - - if ("`notin'"!=""){ - display as error "Data is different, the following variables are in existing vintage" /// - _n "that are not in the new data, overwrite is not possible" - noi dis as error "`notin'" - error 12111 - exit - } - else{ - local check: list tocheckn & tocheck - local cfrc=0 - foreach bb of local check{ - - cap cf `bb' using `current', all - local works = _rc - if (`works'!=0){ - local diffvars `diffvars' `bb' - } - local cfrc = `works' + `cfrc' - - } - if `cfrc'==0{ - return local proceed = 1 - } - else{ - display as error "The following variables do not match, please check: " /// - _n "`diffvars'" - return local proceed = 0 - } - } - use `current', clear - } - else{ - use `current', clear - display as error "I was unable to call" - noi dis in yellow "datalibweb, country(`country') year(`year') verm(`verm') vera(`vera') module(`module') type(gmd) clear" - error 12111 - exit - } - - -end +cap program drop primus_check +program define primus_check, rclass + + version 11.0 + + syntax, country(string) verm(string) vera(string) year(numlist int max=1 >1900) /// + module(string) + + local toup country svy module + + foreach x of local toup{ + if ("``x''"!="") local `x' =trim(upper("``x''")) + } + + foreach x of varlist *{ + local tocheck `tocheck' `x' + } + + cap isid hhid + local hhlev =_rc==0 + if (`hhlev'!=1){ + cap isid hhid pid + if (_rc==0){ + sort hhid pid + } + else{ + dis as error "Data is not at hh or individual level" + error 2343 + exit + } + } + else sort hhid + + tempfile current + save `current' + + cap datalibweb, country(`country') year(`year') verm(`verm') vera(`vera') module(`module') type(gmd) clear nocpi + local nogo = _rc + cap drop cpi* + cap drop icp* + cap drop ppp* + cap drop datalevel + cap replace countrycode=upper(countrycode) + + if (`nogo'==0){ + cap rename weight weight_h + + qui: count + local NN=r(N) + + foreach x of varlist *{ + qui: count if missing(`x') + local NNn=r(N) + if (`NN'!=`NNn') local tocheckn `tocheckn' `x' + } + cap isid hhid + local hhlev =_rc==0 + if (`hhlev'!=1){ + cap isid hhid pid + local indivlev = _rc==0 + if (`indivlev'==1){ + sort hhid pid + } + else{ + dis as error "Data is not at hh or individual level" + error 2343 + exit + } + } + else{ + sort hhid + } + + //Check if there are vars in tocheckn not in tocheck + local notin: list tocheckn - tocheck + + if ("`notin'"!=""){ + display as error "Data is different, the following variables are in existing vintage" /// + _n "that are not in the new data, overwrite is not possible" + noi dis as error "`notin'" + error 12111 + exit + } + else{ + local check: list tocheckn & tocheck + local cfrc=0 + foreach bb of local check{ + + cap cf `bb' using `current', all + local works = _rc + if (`works'!=0){ + local diffvars `diffvars' `bb' + } + local cfrc = `works' + `cfrc' + + } + if `cfrc'==0{ + return local proceed = 1 + } + else{ + display as error "The following variables do not match, please check: " /// + _n "`diffvars'" + return local proceed = 0 + } + } + use `current', clear + } + else{ + use `current', clear + display as error "I was unable to call" + noi dis in yellow "datalibweb, country(`country') year(`year') verm(`verm') vera(`vera') module(`module') type(gmd) clear" + error 12111 + exit + } + + +end diff --git a/p/primus_download.ado b/primus_download.ado similarity index 96% rename from p/primus_download.ado rename to primus_download.ado index a2b0fd8..8f1a63a 100644 --- a/p/primus_download.ado +++ b/primus_download.ado @@ -1,63 +1,63 @@ -*! version 0.0.1 23Feb2018 -*! Copyright (C) World Bank 2017-18 - -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. - -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. - -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . - -capture program define _primus, plugin using("Primus`=cond(strpos(`"`=c(machine_type)'"',"64"),64,32)'.dll") -cap program drop primus_download -program primus_download, rclass - version 11.0 - syntax [anything], [TRANxid(string) ] - local server 3 - local opt 2 - global errcodep 0 - tempfile primusout - if "`tranxid'"~="" { - if `= wordcount("`tranxid'")' > 1 { - local tranxid0 - foreach tranx of local tranxid { - if "`tranxid0'"~="" local tranxid0 "`tranxid0',`tranx'" - else local tranxid0 `tranx' - } - } - else local tranxid0 `tranxid' - tempfile primusout - qui plugin call _primus , "`opt'" "TransactionId=`tranxid0'" "`primusout'" "`server'" - if `primusRC'==0 { - *cap import delimited using "`primusout'", clear - cap insheet using "`primusout'", clear - if _rc==0 { - if _N==0 { - noi dis in yellow "Nothing found based on the input. Please redefine the parameters." - global errcodep = 1 - clear - } - else { - noi dis as text "Successful load the query into Stata!" - global errcodep = 0 - } - } - else { - noi dis as error "Failed to load the data. Please redefine the parameters." - global errcodep = 1 - error 1 - } - } - } //tranxid - else { - noi dis as error "There should be at least one transaction ID" - global errcodep = 1 - error 1 - } -end +*! version 0.0.1 23Feb2018 +*! Copyright (C) World Bank 2017-18 + +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . + +capture program define _primus, plugin using("Primus`=cond(strpos(`"`=c(machine_type)'"',"64"),64,32)'.dll") +cap program drop primus_download +program primus_download, rclass + version 11.0 + syntax [anything], [TRANxid(string) ] + local server 3 + local opt 2 + global errcodep 0 + tempfile primusout + if "`tranxid'"~="" { + if `= wordcount("`tranxid'")' > 1 { + local tranxid0 + foreach tranx of local tranxid { + if "`tranxid0'"~="" local tranxid0 "`tranxid0',`tranx'" + else local tranxid0 `tranx' + } + } + else local tranxid0 `tranxid' + tempfile primusout + qui plugin call _primus , "`opt'" "TransactionId=`tranxid0'" "`primusout'" "`server'" + if `primusRC'==0 { + *cap import delimited using "`primusout'", clear + cap insheet using "`primusout'", clear + if _rc==0 { + if _N==0 { + noi dis in yellow "Nothing found based on the input. Please redefine the parameters." + global errcodep = 1 + clear + } + else { + noi dis as text "Successful load the query into Stata!" + global errcodep = 0 + } + } + else { + noi dis as error "Failed to load the data. Please redefine the parameters." + global errcodep = 1 + error 1 + } + } + } //tranxid + else { + noi dis as error "There should be at least one transaction ID" + global errcodep = 1 + error 1 + } +end diff --git a/p/primus_download.sthlp b/primus_download.sthlp similarity index 95% rename from p/primus_download.sthlp rename to primus_download.sthlp index 5eb99ae..12156a5 100644 --- a/p/primus_download.sthlp +++ b/primus_download.sthlp @@ -1,39 +1,39 @@ -{smcl} -{* *! version 0.0.1 19Jan2018}{...} -{cmd:help primus_download} -{hline} - -{title:Title} - -{p2colset 5 24 26 2}{...} -{p2col :}{cmd:primus download} {hline 1} Download statistics/data from PRIMUS -{p2colreset}{...} - -{marker syntax}{...} -{title:Syntax} - -{p 8 17 2} -{cmdab:primus download} -{cmd:,} -{opt tran:xid(string)}] - -{synoptline} -{p2colreset}{...} - -{marker description}{...} -{title:Description} - -{pstd} -{cmd:primus upload} download the statistics/indicators deposited in PRIMUS based on the microdata uploaded into PRIMUS. - -{marker options}{...} -{title:Options} - -{dlgtab:Optional} - -{synopt:{opth tran:xid(string)}} Transaction IDs separated by space{p_end} - -{marker examples}{...} -{title:Examples} - -{phang}{cmd:. primus download, tranxid(TRN-000408971-MNA-DJI-U0FHW TRN-000408971-MNA-DJI-BD5KM)} {p_end} +{smcl} +{* *! version 0.0.1 19Jan2018}{...} +{cmd:help primus_download} +{hline} + +{title:Title} + +{p2colset 5 24 26 2}{...} +{p2col :}{cmd:primus download} {hline 1} Download statistics/data from PRIMUS +{p2colreset}{...} + +{marker syntax}{...} +{title:Syntax} + +{p 8 17 2} +{cmdab:primus download} +{cmd:,} +{opt tran:xid(string)}] + +{synoptline} +{p2colreset}{...} + +{marker description}{...} +{title:Description} + +{pstd} +{cmd:primus upload} download the statistics/indicators deposited in PRIMUS based on the microdata uploaded into PRIMUS. + +{marker options}{...} +{title:Options} + +{dlgtab:Optional} + +{synopt:{opth tran:xid(string)}} Transaction IDs separated by space{p_end} + +{marker examples}{...} +{title:Examples} + +{phang}{cmd:. primus download, tranxid(TRN-000408971-MNA-DJI-U0FHW TRN-000408971-MNA-DJI-BD5KM)} {p_end} diff --git a/p/primus_message.ado b/primus_message.ado similarity index 98% rename from p/primus_message.ado rename to primus_message.ado index d415581..10beb8b 100644 --- a/p/primus_message.ado +++ b/primus_message.ado @@ -1,39 +1,39 @@ -//error function -cap program drop primus_message -program define primus_message - syntax, error(numlist max=1) - //subscription error - if `error'==2 noi dis "{err}Un-authorized upload into the region that is not assigned to you" - if `error'==3 noi dis "{err}Transaction: Decision by approvers" - if `error'==4 noi dis "{err}Transaction: already reviewed by approvers" - if `error'==5 noi dis "{err}Transaction: is in approved/rejected state, no further action allowed" - if `error'==683 noi dis "{err}Unable to act by the approvers" - if `error'==684 noi dis "{err}Current user not authorized to act on the transaction" - if `error'==685 noi dis "{err}Unable to add comments" - if `error'==686 noi dis "{err}The transaction does not contain the cal_index" - if `error'==687 noi dis "{err}Approver decision would be either Rejected or approved" - if `error'==688 noi dis "{err}Uploader decision would be rejected or confirmed" - if `error'==671 noi dis "{err}File size exceed the PRIMUS upload limit" - if `error'==672 noi dis "{err}Result file's REGION_CODE,SURVEY_ID,FILENAME and RequestKey should not be null or empty" - if `error'==673 noi dis "{err}Unable to update the PRIMUS System with result data" - if `error'==674 noi dis "{err}Unable to Access to network share" - if `error'==675 noi dis "{err}POVCALNET service failed to Process the STATA file" - if `error'==676 noi dis "{err}POVCALNET service return null" - if `error'==677 noi dis "{err}Invalid Result file received from STATA" - if `error'==678 noi dis "{err}There is no transaction exist in PRIMUS system in the name of: {0}" - if `error'==679 noi dis "{err}Invalid Result file received from POVCALNET" - if `error'==682 noi dis "{err}Network error" - //Plugin error - if `error'==601 noi dis "{err}Error code 601 - Internet bad url format" - if `error'==602 noi dis "{err}Error code 602 - Internet authentication canceled" - if `error'==603 noi dis "{err}Error code 603 - Internet connectivity failure" - if `error'==604 noi dis "{err}Error code 604 - Internet datalib server unreachable" - if `error'==605 noi dis "{err}Error code 605 - Internet unknown local error" - if `error'==610 noi dis "{err}Error code 610 - Response error invalid content type header" - if `error'==611 noi dis "{err}Error code 611 - Response error invalid file name header" - if `error'==612 noi dis "{err}Error code 612 - Response error invalid content length header" - if `error'==613 noi dis "{err}Error code 613 - Response error invalid file extension" - if `error'==614 noi dis "{err}Error code 614 - Response error invalid status header" - if `error'==701 noi dis "{err}Error code 701 - Plugin usage error, parameter list" - if `error'==702 noi dis "{err}Error code 702 - File I/O error, local file system access" -end +//error function +cap program drop primus_message +program define primus_message + syntax, error(numlist max=1) + //subscription error + if `error'==2 noi dis "{err}Un-authorized upload into the region that is not assigned to you" + if `error'==3 noi dis "{err}Transaction: Decision by approvers" + if `error'==4 noi dis "{err}Transaction: already reviewed by approvers" + if `error'==5 noi dis "{err}Transaction: is in approved/rejected state, no further action allowed" + if `error'==683 noi dis "{err}Unable to act by the approvers" + if `error'==684 noi dis "{err}Current user not authorized to act on the transaction" + if `error'==685 noi dis "{err}Unable to add comments" + if `error'==686 noi dis "{err}The transaction does not contain the cal_index" + if `error'==687 noi dis "{err}Approver decision would be either Rejected or approved" + if `error'==688 noi dis "{err}Uploader decision would be rejected or confirmed" + if `error'==671 noi dis "{err}File size exceed the PRIMUS upload limit" + if `error'==672 noi dis "{err}Result file's REGION_CODE,SURVEY_ID,FILENAME and RequestKey should not be null or empty" + if `error'==673 noi dis "{err}Unable to update the PRIMUS System with result data" + if `error'==674 noi dis "{err}Unable to Access to network share" + if `error'==675 noi dis "{err}POVCALNET service failed to Process the STATA file" + if `error'==676 noi dis "{err}POVCALNET service return null" + if `error'==677 noi dis "{err}Invalid Result file received from STATA" + if `error'==678 noi dis "{err}There is no transaction exist in PRIMUS system in the name of: {0}" + if `error'==679 noi dis "{err}Invalid Result file received from POVCALNET" + if `error'==682 noi dis "{err}Network error" + //Plugin error + if `error'==601 noi dis "{err}Error code 601 - Internet bad url format" + if `error'==602 noi dis "{err}Error code 602 - Internet authentication canceled" + if `error'==603 noi dis "{err}Error code 603 - Internet connectivity failure" + if `error'==604 noi dis "{err}Error code 604 - Internet datalib server unreachable" + if `error'==605 noi dis "{err}Error code 605 - Internet unknown local error" + if `error'==610 noi dis "{err}Error code 610 - Response error invalid content type header" + if `error'==611 noi dis "{err}Error code 611 - Response error invalid file name header" + if `error'==612 noi dis "{err}Error code 612 - Response error invalid content length header" + if `error'==613 noi dis "{err}Error code 613 - Response error invalid file extension" + if `error'==614 noi dis "{err}Error code 614 - Response error invalid status header" + if `error'==701 noi dis "{err}Error code 701 - Plugin usage error, parameter list" + if `error'==702 noi dis "{err}Error code 702 - File I/O error, local file system access" +end diff --git a/p/primus_query.ado b/primus_query.ado similarity index 97% rename from p/primus_query.ado rename to primus_query.ado index 05ee7d8..1cb0e65 100644 --- a/p/primus_query.ado +++ b/primus_query.ado @@ -1,103 +1,103 @@ -*! version 0.0.1 23Feb2018 -*! Copyright (C) World Bank 2017-18 - -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. - -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. - -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . - -capture program define _primus, plugin using("Primus`=cond(strpos(`"`=c(machine_type)'"',"64"),64,32)'.dll") -cap program drop primus_query -program primus_query, rclass - version 11.0 - syntax [anything] [, /// - COUNtry(string) Year(string) /// - Region(string) OVERALLStatus(string) /// - PENDINGwith(string) TRANxid(string)] - - local opt 1 - local server 3 - global errcodep = 0 - //housekeeping - local regionlist `" "ECA", "EAP", "MNA", "LAC", "SSA", "SAR" "' - local overallstatuslist `" "APPROVED", "PENDING", "REJECTED" "' - local pendingwithlist `" "DECDG", "FINALIZER", "POVCALNET", "REGIONAL", "UPLOADER" "' - - local yearkey DataYear - local countrykey Country - local regionkey Region - local overallstatuskey OverallStatus - local pendingwithkey Pendingwith - local tranxidkey TransactionId - - local RequestKey - - local loclist country year region overallstatus pendingwith tranxid - foreach loc of local loclist { - if "``loc''" ~="" { - local `loc' `=upper("``loc''")' - if "`loc'"=="country" | "`loc'"=="year" | "`loc'"=="tranxid" { - local `loc' : subinstr local `loc' " " "", all - if "`RequestKey'"=="" local RequestKey ``loc'key'=``loc'' - else local RequestKey `RequestKey'&``loc'key'=``loc'' - } - else { //other locs with checks - if `=wordcount("``loc''")' > 1 { - noi disp in red `"The input on the `loc'() is not correct. Available options are: ``loc'list'; and one region at a time."' - global errcodep = 198 - error 198 - } - else { - if (!inlist("``loc''",``loc'list')) { - noi disp in red `"The input on the region() is not correct. Available options are: ``loc'list'."' - global errcodep = 198 - error 198 - } - else { - if "`RequestKey'"=="" local RequestKey ``loc'key'=``loc'' - else local RequestKey `RequestKey'&``loc'key'=``loc'' - } - } - } - } //real loc - } //loclist - - //getting API - tempfile primusout - qui plugin call _primus , "`opt'" "`RequestKey'" "`primusout'" "`server'" - if `primusRC'==0 { - cap insheet using "`primusout'", clear - if _rc==0 { - if _N==0 { - cap confirm numeric variable transaction_id - if _rc==0 { - noi dis in yellow "Nothing found based on the input. Please redefine the parameters." - global errcodep = 1 - clear - } - } - else { - noi dis as text "Successful load the query data into Stata!" - global errcodep = 0 - gen double date_modified1 = clock(date_modified, "MDYhms") - format %tc date_modified1 - drop date_modified - ren date_modified1 date_modified - } - } //rc insheet - else { - noi dis as error "Failed to load the data. Please redefine the parameters." - global errcodep = 1 - error 1 - } - } //rc primus - -end +*! version 0.0.1 23Feb2018 +*! Copyright (C) World Bank 2017-18 + +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. + +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. + +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . + +capture program define _primus, plugin using("Primus`=cond(strpos(`"`=c(machine_type)'"',"64"),64,32)'.dll") +cap program drop primus_query +program primus_query, rclass + version 11.0 + syntax [anything] [, /// + COUNtry(string) Year(string) /// + Region(string) OVERALLStatus(string) /// + PENDINGwith(string) TRANxid(string)] + + local opt 1 + local server 3 + global errcodep = 0 + //housekeeping + local regionlist `" "ECA", "EAP", "MNA", "LAC", "SSA", "SAR" "' + local overallstatuslist `" "APPROVED", "PENDING", "REJECTED" "' + local pendingwithlist `" "DECDG", "FINALIZER", "POVCALNET", "REGIONAL", "UPLOADER" "' + + local yearkey DataYear + local countrykey Country + local regionkey Region + local overallstatuskey OverallStatus + local pendingwithkey Pendingwith + local tranxidkey TransactionId + + local RequestKey + + local loclist country year region overallstatus pendingwith tranxid + foreach loc of local loclist { + if "``loc''" ~="" { + local `loc' `=upper("``loc''")' + if "`loc'"=="country" | "`loc'"=="year" | "`loc'"=="tranxid" { + local `loc' : subinstr local `loc' " " "", all + if "`RequestKey'"=="" local RequestKey ``loc'key'=``loc'' + else local RequestKey `RequestKey'&``loc'key'=``loc'' + } + else { //other locs with checks + if `=wordcount("``loc''")' > 1 { + noi disp in red `"The input on the `loc'() is not correct. Available options are: ``loc'list'; and one region at a time."' + global errcodep = 198 + error 198 + } + else { + if (!inlist("``loc''",``loc'list')) { + noi disp in red `"The input on the region() is not correct. Available options are: ``loc'list'."' + global errcodep = 198 + error 198 + } + else { + if "`RequestKey'"=="" local RequestKey ``loc'key'=``loc'' + else local RequestKey `RequestKey'&``loc'key'=``loc'' + } + } + } + } //real loc + } //loclist + + //getting API + tempfile primusout + qui plugin call _primus , "`opt'" "`RequestKey'" "`primusout'" "`server'" + if `primusRC'==0 { + cap insheet using "`primusout'", clear + if _rc==0 { + if _N==0 { + cap confirm numeric variable transaction_id + if _rc==0 { + noi dis in yellow "Nothing found based on the input. Please redefine the parameters." + global errcodep = 1 + clear + } + } + else { + noi dis as text "Successful load the query data into Stata!" + global errcodep = 0 + gen double date_modified1 = clock(date_modified, "MDYhms") + format %tc date_modified1 + drop date_modified + ren date_modified1 date_modified + } + } //rc insheet + else { + noi dis as error "Failed to load the data. Please redefine the parameters." + global errcodep = 1 + error 1 + } + } //rc primus + +end diff --git a/p/primus_query.sthlp b/primus_query.sthlp similarity index 97% rename from p/primus_query.sthlp rename to primus_query.sthlp index a461cea..fa23726 100644 --- a/p/primus_query.sthlp +++ b/primus_query.sthlp @@ -1,58 +1,58 @@ -{smcl} -{* *! version 0.0.1 19Jan2018}{...} -{cmd:help primus_query} -{hline} - -{title:Title} - -{p2colset 5 24 26 2}{...} -{p2col :}{cmd:primus query} {hline 1} Query the status of the PRIMUS transactions -{p2colreset}{...} - -{marker syntax}{...} -{title:Syntax} - -{p 8 17 2} -{cmdab:primus query} -{cmd:,[} -{opt coun:try(string)} {opt year(string)} {opt r:egion(string)} {opt overalls:tatus(string)} {opt pending:with(string)} {opt tran:xid(string)}] - -{synoptline} -{p2colreset}{...} - -{marker description}{...} -{title:Description} - -{pstd} -{cmd:primus query} Query the status of the PRIMUS transactions and load it into Stata. Users can filter the results by different optional parameters. There should be at least one parameter in usage. - -{marker options}{...} -{title:Options} - -{dlgtab:Optional} - -{synopt:{opth coun:try(string)}} Three-letter country code; can accept more than one country code separated by comma{p_end} -{synopt:{opth year(string)}} year of the data; can accept more than one year separated by comma{p_end} -{synopt:{opth r:egion(string)}} region of the data and transaction. Options are "ECA", "EAP", "MNA", "LAC", "SSA", or "SAR"{p_end} -{synopt:{opth overalls:tatus(string)}} The overall status of the transaction. It can be "APPROVED", "PENDING", or "REJECTED", and takes only one value{p_end} -{synopt:{opth pending:with(string)}} Find the pending status from approvers, and only take one value. Option is "DECDG", "FINALIZER", "POVCALNET", "REGIONAL", or "UPLOADER"{p_end} -{synopt:{opth tran:xid(string)}} Transaction IDs, can accept more than one transaction separated by comma{p_end} - -{marker examples}{...} -{title:Examples} - -{phang}{cmd:. primus query, overallstatus(PENDING)} {p_end} -{pstd} -Query the status of the PRIMUS transactions with the overall status as PENDING. - -{phang}{cmd:. primus query, country(ALB,ARM) overalls(pending)} {p_end} -{pstd} -Query the status of the PRIMUS transactions for ALB and ARM with the overall status as PENDING. - -{phang}{cmd:. primus query, region(ECA) overalls(pending)} {p_end} -{pstd} -Query the status of all PRIMUS transactions from the ECA region with the overall status as PENDING. - -{phang}{cmd:. primus query, region(ECA) pending(povcalnet)} {p_end} -{pstd} -Query the status of all PRIMUS transactions from the ECA region with the overall status as PENDING with Povcalnet. +{smcl} +{* *! version 0.0.1 19Jan2018}{...} +{cmd:help primus_query} +{hline} + +{title:Title} + +{p2colset 5 24 26 2}{...} +{p2col :}{cmd:primus query} {hline 1} Query the status of the PRIMUS transactions +{p2colreset}{...} + +{marker syntax}{...} +{title:Syntax} + +{p 8 17 2} +{cmdab:primus query} +{cmd:,[} +{opt coun:try(string)} {opt year(string)} {opt r:egion(string)} {opt overalls:tatus(string)} {opt pending:with(string)} {opt tran:xid(string)}] + +{synoptline} +{p2colreset}{...} + +{marker description}{...} +{title:Description} + +{pstd} +{cmd:primus query} Query the status of the PRIMUS transactions and load it into Stata. Users can filter the results by different optional parameters. There should be at least one parameter in usage. + +{marker options}{...} +{title:Options} + +{dlgtab:Optional} + +{synopt:{opth coun:try(string)}} Three-letter country code; can accept more than one country code separated by comma{p_end} +{synopt:{opth year(string)}} year of the data; can accept more than one year separated by comma{p_end} +{synopt:{opth r:egion(string)}} region of the data and transaction. Options are "ECA", "EAP", "MNA", "LAC", "SSA", or "SAR"{p_end} +{synopt:{opth overalls:tatus(string)}} The overall status of the transaction. It can be "APPROVED", "PENDING", or "REJECTED", and takes only one value{p_end} +{synopt:{opth pending:with(string)}} Find the pending status from approvers, and only take one value. Option is "DECDG", "FINALIZER", "POVCALNET", "REGIONAL", or "UPLOADER"{p_end} +{synopt:{opth tran:xid(string)}} Transaction IDs, can accept more than one transaction separated by comma{p_end} + +{marker examples}{...} +{title:Examples} + +{phang}{cmd:. primus query, overallstatus(PENDING)} {p_end} +{pstd} +Query the status of the PRIMUS transactions with the overall status as PENDING. + +{phang}{cmd:. primus query, country(ALB,ARM) overalls(pending)} {p_end} +{pstd} +Query the status of the PRIMUS transactions for ALB and ARM with the overall status as PENDING. + +{phang}{cmd:. primus query, region(ECA) overalls(pending)} {p_end} +{pstd} +Query the status of all PRIMUS transactions from the ECA region with the overall status as PENDING. + +{phang}{cmd:. primus query, region(ECA) pending(povcalnet)} {p_end} +{pstd} +Query the status of all PRIMUS transactions from the ECA region with the overall status as PENDING with Povcalnet. diff --git a/p/primus_up.ado b/primus_up.ado similarity index 97% rename from p/primus_up.ado rename to primus_up.ado index dd51ee7..16c5ffc 100644 --- a/p/primus_up.ado +++ b/primus_up.ado @@ -1,1051 +1,1051 @@ -*! primus_up.ado -*! December 2019 - -cap program drop primus_up -cap set matastrict off -program define primus_up, eclass - version 11.2 - syntax, /// - output(string) /// - NATcode(string) /// - YEARs(numlist >1900 min=1) /// - refyear(string) /// - WEFlist(varlist max=1) /// - VERMast_p(string) /// - VERAlt_p(string) /// - SURveys(string) /// - FILEname(string) /// - reg(string) /// - ctryname(string) /// - no_pweight(numlist max=1) /// - povweight(varname) /// - filename(string) /// - nopovcal(numlist max=1) /// - collection(string) /// - [SURVName(string) cpimethod(string) filepath(string) hhlev(integer 0) byvar(varname)] - -//Declare locals -local date1 = c(current_date) -local date2 : subinstr local date1 ":" "_", all -global output ="`output'" -global file0 ="primus_`date2'" -global dd ="uploading" -local aa 1 -local ccounT = "`natcode'" -local fname = "`filename'" - -tokenize `surveys', parse(_) -local mysvynm `5' -local mysvyY `3' -local myVM `7' -local myVA `11' - -//Ensure always sorted -cap isid hhid -local itis = _rc -if (`itis'==0) sort hhid -else sort hhid pid - -if ("`cpimethod'"=="") local method CustomCPI - -if (`no_pweight'==1 & `itis'!=0){ -// If the data is HH level and the user did not provide a weight, then by default -// weight_p and weight_i will be equal, thus no check is required. The check is only -// necessary iff you have individual level data and you did not provide a povweight - preserve - - tempvar popw povw - egen double `povw' = sum(weight_p*(weight_h!=. & hsize!=.)), by(hhid) - gen double `popw' = weight_h*hsize - - count if abs(`povw' - `popw')>0.01 & `povw'!=. & `popw'!=. - local dif = r(N) - if (`dif'>0){ - display as error "You need to specify weights to ensure replication of poverty at the individual and household level" - error 100 - exit - } - restore -} - -//To ensure old codes run -rename weight_p weight - - - -// Check what versions to compare to: -preserve -primus_vintage, country(`natcode') year(`years') wrk svy(`mysvynm') -local gpwg_wm = r(gpwg_wm) - local gpwg_wm = subinstr("`gpwg_wm'", ".","",.) -local gpwg_m = r(gpwg_m) - local gpwg_m = subinstr("`gpwg_m'", ".","",.) -local gpwg_a = r(gpwg_a) - local gpwg_a = subinstr("`gpwg_a'", ".","",.) -local newy = r(newy) -restore - -// Check to verify if Working Version has to be compared - -if ("`gpwg_wm'"!=""){ - //need natcode years surveys - preserve - qui: cap primus_query, country(`natcode') year(`years') - local qwrk = _rc==0 - if (`qwrk'==1){ - keep if regexm(survey_id,"`surveys'")==1 - keep if trim(lower(overall_status))=="pending" & trim(lower(uploader))=="true" - *set trace on - *set traced 1 - if (_N==0) local donotcompare = 1 - else{ - split survey_id, parse(_) - keep if trim(upper(survey_id4))==upper("`vermast_p'") & /// - upper(survey_id6)==upper("`veralt_p'") & (trim(lower(regional))=="pending"|trim(lower(uploader))=="false") - if (_N!=0){ - egen double maxdate =max(date_modified) - levelsof transaction_id if maxdate==date_modified, local(_tid) - - capture window stopbox rusure "Do you want to clear transid `_tid' from memory?" /// - "`filename'" - local stwrk = _rc==0 - - if (`stwrk'==1){ - primus_action, tranxid(`_tid') comments("Cancelled by `c(username)' through Primus upload process") /// - decision("REJECTED") - local donotcompare=1 - } - else{ - dis as error "You may not overwrite data with pending transaction id's" - error 238374 - exit - } - } - else local donotcompare = 0 - } - } - else{ - display as error "Unable to load query data, please try again" - error 3949444 - exit - } - restore -} -else{ -//verify older vintages - preserve - qui: cap primus_query, country(`natcode') year(`years') - local qwrk = _rc==0 - if (`qwrk'==1){ - if _N!=0{ - keep if regexm(lower(survey_id),lower("`mysvynm'"))==1 - egen double maxdate =max(date_modified) - drop if maxdate < `=clock("1 Jan 2018 00:00:00","DMY hms")' - - if (_N==0) local donotcompare = 0 - else{ - levelsof transaction_id if lower(survey_id)==lower("`surveys'") & lower(uploader)=="false" & lower(overall_status)=="pending", local(mytrans) - foreach id of local mytrans{ - primus_action, tranxid(`id') comments("Cancelled by `c(username)' through Primus upload process") /// - decision("REJECTED") - } - - if (_N==0) local donotcompare = 1 - else local donotcompare = 0 - - } - } - else local donotcompare = 1 - } - else{ - display as error "Unable to load query data, please try again" - error 3949444 - exit - } - restore -} //END ELSE - -//Compare data to previous vintages, or current working versions!! -if ("`collection'"=="GMD"){ - if (`donotcompare'==0){ - noi:primuSCompaRe, newy(`newy') natcode(`natcode') year(`years') gpwg_a(`gpwg_a') gpwg_m(`gpwg_m') gpwg_wm(`gpwg_wm') hhlev(`hhlev') reg(`reg') - local gotoprimus=r(gotoprimus) - } - else local gotoprimus = 1 -} -else{ - local gotoprimus=1 -} - - -//Keep only one weight type if GPWG - if (regexm("`filename'","GPWG")==1){ - cap drop weight_h - cap rename weight_p weight - local theW weight - } - else{ - cap rename weight weight_p - local theW weight_p - } - - if ("`gotoprimus'"!="1" & `nopovcal'!=1){ - dis as error "You have not specified the nopovcal option, and thus data will not be submitted for confirmation" - error 29024 - exit - } - - if ("`gotoprimus'"=="1" & `nopovcal'==1){ - dis as error "Your data needs to be uploaded to povcalnet and trigger a transaction ID" - error 2929292 - exit - } - - local ccc `natcode' - local yyy `years' - di in red "`ccc':`yyy':`surveys':`vermast_p':`veralt_p'" - - tempfile MuDAta - save `MuDAta' - -//Price database! - qui datalibweb, country(Support) year(2005) type(GMDRAW) surveyid(Support_2005_CPI_v04_M) filename(Final_CPI_PPP_to_be_used.dta) clear - di r(cmdline) - local priceproblem=_rc - if (`priceproblem'==111|`priceproblem'==0){ - cap keep if upper(code)==upper("`ccc'") - if (_rc) keep if upper(countrycode)==upper("`ccc'") - tempfile cpi_ - save `cpi_' - } - else{ - dis as error "Unable to load price database" - error 128384 - exit - } - - use `MuDAta', clear - -//Datalevel - if ("`=upper("`ccc'")'"=="IDN" | "`=upper("`ccc'")'"=="CHN" | "`=upper("`ccc'")'"=="IND"){ - gen datalevel = 1 - local method EmbeddedCPI - } - else { - gen datalevel = 2 - } - -//Merge CPI - cap gen code = "`=upper("`ccc'")'" - cap drop cpi* - cap drop icp* - - if (strpos("`surveys'","EU-SILC")>0 | strpos("`surveys'","SILC")>0) replace year = year - 1 - - cap drop region - ren survey survname - qui merge m:1 code year datalevel survname using `cpi_', gen(_mcpi) keepus(region countryname ref_year cpi2011 icp2011) - ren survname survey - - * Display error if CPI data cannot be merged into the dataset being uploaded - *ta _mcpi - qui count if _mcpi==1 //Count observations that could not be merged with CPI data - if r(N) !=0{ - dis as error "Your survey could not be fully merged with CPI data. Please contact the Central Team and review Final_CPI_PPP_to_be_used.dta." - error 12345 - } - * qui merge m:1 code year datalevel using `cpi_', gen(_mcpi) keepus(region countryname ref_year cpi2011 icp2011) //SM19 code - - qui drop if _mcpi==2 - qui drop _mcpi - cap drop datalevel - cap drop ppp_note - -//define deflators - local cpi cpi2011 - local ppp icp2011 - if (strpos("`surveys'","EU-SILC")>0 | strpos("`surveys'","SILC")>0) replace year = year + 1 - - local refyr = `refyear' - if ("`refyr'"=="."|strpos("`surveys'","SILC")>0){ - if (strpos("`surveys'","EU-SILC")>0 | strpos("`surveys'","SILC-C")>0) local refyr `=`yyy'-1' - else local refyr `yyy' - } - -tempfile dataout -save `dataout',replace -cap log close logall - - - ***************************** XML *************************** - //Prepare the files and naming structures. - local date = c(current_date) - local time = c(current_time) - local datetime `date' `time' - - //Indicator calculation - XML - tempfile xmlout logfile - log using "`logfile'", text replace name(logall) - - //Setup for XML - //local byvar - local countrycode `ccc' - local pppyear 2011 - local surveyid `surveys' - local filename `fname' - local year `yyy' - - - if "`weflist'"=="" local weflist welfare - if "`weightlist'"=="" local weightlist `theW' - if "`pppyear'"=="" local pppyear 2011 - if "`plines'"=="" { - if `pppyear'==2011 local plines 1.9 3.2 - if `pppyear'==2005 local plines 1.25 2.0 - } - - - log off logall - - //new values - dis %10.0g - levelsof `cpi', local(newCPIValue) - levelsof `ppp', local(newPPPValue) - - local cpilist `newCPIValue' - local icplist `newPPPValue' - - display in red "`icplist'" - display in red "`cpilist'" - //adjust local - local weflist = trim("`weflist'") - local weflist1 : subinstr local weflist "`=char(32)'" ",", all - local weightlist = trim("`weightlist'") - if (`: word count `weightlist''>1) & (`: word count `weflist''>1) & (`: word count `weightlist'' < `: word count `weflist'') { - dis in red "No balanced pairs of welfare and weight variables" - exit 198 - } - if (`: word count `weightlist''==1) & (`: word count `weflist''>1) { - local weightlist = "`weightlist' " * `: word count `weflist'' - } - - local weightlist = trim("`weightlist'") - local weightlist1 : subinstr local weightlist "`=char(32)'" ",", all - - local wset - forv j=1(1)`: word count `weflist'' { - local wf : word `j' of `weflist' - local wt : word `j' of `weightlist' - local wset "`wset' `wf'|`wt'" - } - local wset = trim("`wset'") - local wset : subinstr local wset "`=char(32)'" ",", all - - //reload the data - use `dataout', clear - - //byvar check - if "`byvar'"~="" { - ta `byvar' - local nbyvar = r(r) - local byvar2 `byvar' - } - else { - local nbyvar 1 - gen __all__ = 1 - la def __all__ 1 "All sample" - la val __all__ __all__ - local byvar2 __all__ - } - - //count number of requests - local nwevar : word count `weflist' - local nwivar : word count `weightlist' - local npline : word count `plines' - local nParamSets = `npline' - - local paset - foreach vicp of local icplist{ - foreach vcpi of local cpilist{ - foreach pline of local plines{ - if "`method'"=="CustomCPI" local paset "`paset'&Param=Method=`method'|PL=`pline'|PPP=`vicp'|CPI=`vcpi'" - if "`method'"=="EmbeddedCPI" local paset "`paset'&Param=Method=`method'|PL=`pline'" - } - } - } - display in yellow "`paset'" - - //invalid group results can be written as "n/a" - log on logall - - local RequestKey task=Povcal&DataSource=InboundDTA&CountryCode=`countrycode'&DataYear=`year'&By=`byvar'&BaseYear=`pppyear'&welfareSet=`wset'`paset' - dis in yellow "`RequestKey'" - local APP_ID Stata - local DATETIME `datetime' - local IS_INTERPOLATED FALSE - local USE_MICRODATA TRUE - //UNIT_OBS: HH or IND - local UNIT_OBS - local COUNTRY_CODE `countrycode' - local COUNTRY_NAME `ctryname' - local SURVEY_ID `surveyid' - local FILENAME `filename' - local REGION_CODE `reg' - local DATA_COVERAGE 3 - local DATA_TYPE 0 - local DATA_YEAR `year' - local REF_YEAR `refyr' - local CPI_YEAR `refyr' - local PPP_YEAR `pppyear' - log off logall - - //PRIMUS log - tempfile outdata - tempname outfile - file open `outfile' using "`outdata'", read write text - file write `outfile' `""' _n - file write `outfile' _col(2) `""' _n - file write `outfile' _col(4) `""' _n - file write `outfile' _col(4) `"`weflist1'"' _n - file write `outfile' _col(4) `"`weightlist1'"' _n - file write `outfile' _col(4) `"`byvar'"' _n - file write `outfile' _col(4) `"`nbyvar'"' _n - file write `outfile' _col(4) `"`nParamSets'"' _n - file write `outfile' _col(4) `""' _n - file write `outfile' _col(2) `""' _n - file write `outfile' _col(2) `""' _n - - //List of important Char - char _dta[uploaddate] `DATETIME' - char _dta[filename] `FILENAME' - char _dta[survey_id] `SURVEY_ID' - char _dta[use_microdata] `USE_MICRODATA' - char _dta[unit_observation] `UNIT_OBS' - char _dta[ref_year] `refyr' - char _dta[data_year] `DATA_YEAR' - - //Chars for priceframework - - preserve - tokenize `surveys', parse(_) - local _milhouse `5' - if (inlist(upper("`code'"), "CHN", "IDN", "IND")==1) MyPriCeData, code(`natcode') year(`years') survey(`_milhouse') datalevel(N) - else MyPriCeData, code(`natcode') year(`years') survey(`_milhouse') - - restore - - local pricevars `r(_pricevars)' - foreach price of local pricevars{ - char _dta[`price'] `r(_`price')' - } - - - tempfile data0 - save `data0', replace - - log off logall - local j = 1 - - foreach var of local weflist { - use `data0', clear - local wt : word `j' of `weightlist' - //welfare and weight - file write `outfile' _col(4) `""' _n - log on logall - - //Byvar - dis "//Type the below to call your data only if it has already been confirmed and approved" - dis "datalibweb, country(`ccc') year(`yyy') vera(`veralt_p') verm(`vermast_p') type(`collection') module(gpwg) clear" - dis "//Type the below to call your data if it has only been confirmed, but not approved" - dis "datalibweb, country(`ccc') year(`yyy') vera(WRK) verm(`vermast_p') type(`collection') module (gpwg) clear" - dis "gen double `var'_PPP = `var'/ `cpi' / `icp' /365" - dis "su `var' [aw=`wt']" - su `var' [aw=`wt'] - local TotalPopAll = `=r(sum_w)'/1000000 - levelsof `byvar2', local(bylist) - foreach byv of local bylist { - use `data0', clear - keep if `byvar2'==`byv' - tempfile data2 - save `data2', replace - - //data summary - su `var' [aw=`wt'] - local nRecs = r(N) - local TotalPopulation = `=r(sum_w)'/1000000 - local Mean_LCU = r(mean) - local TotalWealth_LCU = r(sum) - local Min_LCU = r(min) - local Max_LCU = r(max) - dis "ainequal `var' [aw=`wt'], all" - noi:ainequal `var' [aw=`wt'],all - local Gini = 100*`=r(gini_1)' - local MLD = 100*`=r(mld_1)' - *local PPPadjuster 1 - sort `var' - _ebin `var' [fw=`wt'], gen(deciles) nq(10) - gen double a = `var'*`wt' - collapse (sum) a, by(deciles) - egen double all = total(a) - gen double share = a/all - sort deciles - forv i=1(1)10 { - local Decile`i' = 100*share[`i'] - } - - log off logall - //byCondition - when there is nothing NULL - //write PRIMUS LOG - bygroup - if "`byvar2'"=="__all__" file write `outfile' _col(4) `""' _n - else file write `outfile' _col(4) `""' _n - file write `outfile' _col(6) `""' _n - file write `outfile' _col(8) `""' _n - file write `outfile' _col(6) `""' _n - - //calculation on poverty - //repeat as needed (different CPI/PPP and povlines) - //forv j=1(1)`nParamSets' { - if "`method'"=="CustomCPI" { //CustomCPI on the query - foreach vicp of local icplist { - foreach vcpi of local cpilist { - foreach pline of local plines { - use `data2', clear - //gen `var'_PPP = `var'/cpi`pppyear'/icp`pppyear'/365 - gen double `var'_PPP = `var'/`vcpi'/`vicp'/365 - local METHOD "`method'" - local PPPValue = `vicp' - local CPIValue = `vcpi' - su `var'_PPP [aw=`wt'] - local ReqYearPopulation = `=r(sum_w)'/1000000 - local MeanPPP = r(mean) - local PovertyLine_LCU = `=`pline'*`PPPValue'*`CPIValue'' - local PovertyLine_PPP = `pline' - local PPPadjuster = `PPPValue'*`CPIValue' - local ByVarShare = (`ReqYearPopulation'/`TotalPopAll')*100 - - log on logall - dis "apoverty `var'_PPP [aw=`wt'], line(`pline') all" - noi: apoverty `var'_PPP [aw=`wt'], line(`pline') all - local Headcount = `=r(head_1)' - local PovertyGap = `=r(pogapr_1)' - local PovertyGapSquared = `=r(fogto3_1)' - local Watt = `=r(watts_1)' - local Npoor = (`Headcount'*`ReqYearPopulation')/100 - log off logall - - //calculation log - file write `outfile' _col(6) `""' _n - file write `outfile' _col(8) `""' _n - file write `outfile' _col(6) `""' _n - } // nparamset pline - } - } - } - if "`method'"=="EmbeddedCPI" { //CPI PPP in the data - foreach pline of local plines { - use `data2', clear - //check tosee if CPI and PPP are constant within groups - qui su `cpi' - if r(sd) ~= 0 { - dis as error "CPI values should be constant within a group - `byvar2'==`byv'" - error 198 - } - qui su `ppp' - if r(sd) ~= 0 { - dis as error "ICP/PPP values should be constant within a group - `byvar2'==`byv'" - error 198 - } - gen `var'_PPP = `var'/ `cpi' / `ppp' /365 - //gen `var'_PPP = `var'/`cpi'/`icp'/365 - local METHOD "`method'" - local PPPValue = `icp'[1] - local CPIValue = `cpi'[1] - - noi dis in yellow "`CPIValue'" - su `var'_PPP [aw=`wt'] - local ReqYearPopulation = `=r(sum_w)'/1000000 - local MeanPPP = r(mean) - local PovertyLine_LCU = `=`pline'*`PPPValue'*`CPIValue'' - local PovertyLine_PPP = `pline' - local PPPadjuster = `PPPValue'*`CPIValue' - local ByVarShare = (`ReqYearPopulation'/`TotalPopAll')*100 - - log on logall - dis "apoverty `var'_PPP [aw=`wt'], line(`pline') all" - noi:apoverty `var'_PPP [aw=`wt'], line(`pline') all - local Headcount = `=r(head_1)' - local PovertyGap = `=r(pogapr_1)' - local PovertyGapSquared = `=r(fogto3_1)' - local Watt = `=r(watts_1)' - local Npoor = (`Headcount'*`ReqYearPopulation')/100 - log off logall - - //calculation log - file write `outfile' _col(6) `""' _n - file write `outfile' _col(8) `""' _n - file write `outfile' _col(6) `""' _n - } // nparamset pline - } - file write `outfile' _col(4) `""' _n - } //byvar - log off logall - file write `outfile' _col(4) `""' _n - local j = `j' + 1 - } //welfare - - - //end - file write `outfile' _col(2) `""' _n - log close logall - - //LOG Detail code - clear - qui set obs 1 - tempname note docout mystr - file write `outfile' _col(2) `""' _n - file write `outfile' _col(8) `""' _n - file write `outfile' _col(2) `""' _n - file write `outfile' `""' - file close `outfile' - qui capture copy "`outdata'" "`xmlout'", replace - if _rc { - display as error "file can not be saved at this location" - exit 603 - } - else { - noi display in yellow "XML File saved in: `xmlout'" - } - - - //Compress the file - use `data0', clear - cap drop __0* - cap drop __all__ - if "`method'"=="CustomCPI" local vlist min max cpi ppp cpi2005 icp2005 icp2011 cpi2011 icpbase cpiy conversion ipc05_sedlac ipc_sedlac filename suryear1 suryear2 weightcheck weightcheck2 update upldatetime username year_adj year_alt datasignature lvlvalue lvlvar - if "`method'"=="EmbeddedCPI" local vlist min max cpi ppp cpiy conversion ipc05_sedlac ipc_sedlac filename suryear1 suryear2 weightcheck weightcheck2 update upldatetime username year_adj year_alt datasignature lvlvalue lvlvar - foreach var of local vlist { - cap drop `var' - } - cap ren subnatid1 subnatid - cap drop region - - //need to add in the SurveyID, filename, data level (hh or ind), micro vs grouped, data date - - //Variabels go into characteristics - local constantlist weighttype welfaretype welfshprtype weighttype survey vermast veralt harmonization cpiperiod level ref_year - foreach var of local constantlist { - cap des `var' - if _rc==0 { - //check if the variables are really constant - cap confirm numeric variable `var' - if _rc==0 { - qui su `var' - if r(sd)==0 { - char _dta[`var'] `=`var'[1]' - cap drop `var' - } - } - else { //string - qui ta `var' - if r(r)==1 { - char _dta[`var'] `=`var'[1]' - cap drop `var' - } - } - } - } - - compress - cap drop cpi* - cap drop icp* - cap datasignature set - if (_rc!=0) datasignature set, reset - saveold `dataout', replace - - copy `xmlout' "C:\Users\\`c(username)'\\Downloads\_XML", replace - if (`nopovcal'==0){ - if (`gotoprimus'==1){ - //Send the file and log - //set trace on - tempfile resultfile - local plusdir "`c(sysdir_plus)'" - cap program define _primus, plugin using("`plusdir'\p\Primus`=cond(strpos(`"`=c(machine_type)'"',"64"),64,32)'.dll") - cap plugin call _primus , "0" "`xmlout'" "`dataout'" "`surveyid'" "`resultfile'" "3" - if _rc==0 { - ereturn local transid "`primusTxId'" - insheet using "`resultfile'", noname clear - noi dis - loc ++aa - qui putexcel A`aa'=("`surveys'") B`aa'=("Uploaded") - noi:display in yellow "PRIMUS YES:`ccc':`yyy'" - - } - else { - noi: display as error "Unable to upload data to system" - loc ++aa - qui putexcel A`aa'=("`surveys'") B`aa'=("Not uploaded") - noi: display in yellow "NO:`ccc':`yyy'" - error 233093 - } - } - } - else{ - - saveold "`filepath'//`filename'", replace - display as error "Your data has been saved to: " - display as error "`filepath'/`filename' " - display as error "Please inform the Central Team (mnguyen3@worldbank.org) about this upload." - } - - -end - - -program define primuSCompaRe, rclass -version 11.2 -syntax, [newy(numlist) natcode(string) year(numlist) reg(string) gpwg_a(string) gpwg_m(string) gpwg_wm(string) hhlev(integer 0)] - - -if (`hhlev'==0){ - if (`newy'==0){ - if ("`gpwg_wm'"==""){ - preserve - noi: dis in red "datalibweb, country(`natcode') year(`year') vera(`gpwg_a') verm(`gpwg_m') type(gmd) mod(gpwg) clear" - cap datalibweb, country(`natcode') year(`year') vera(`gpwg_a') verm(`gpwg_m') type(gmd) mod(gpwg) clear - local _dwcall=_rc - if (`_dwcall'!=0){ - dis as error "I was unable to call: datalibweb, country(`natcode') year(`years') vera(`gpwg_a') verm(`gpwg_m') type(gmd) type(gpwg) clear " - exit - } - else{ - cap isid hhid - if (_rc==0) sort hhid - else{ - cap sort hhid pid - if _rc!=0 sort hhid - } - cap recast float weight, force - cap recast float welfare, force - - tempfile tocmp - save `tocmp' - } - restore - - cap recast float weight, force - cap recast float welfare, force - - - cap cf welfare weight using `tocmp', verbose - local cfrc = _rc - if `cfrc'==0{ - local gotoprimus = 0 - dis as error "Your new vintage does not update welfare or weights, data will not be uploaded through Primus" - exit - } - else{ - noi: display in y "Your new vintage updates welfare or weights, data will be uploaded through Primus" - local gotoprimus = 1 - } - } - else{ //compare to WRK version - preserve - cap datalibweb, country(`natcode') year(`year') vera(WRK) verm(`gpwg_wm') type(gmd) mod(gpwg) clear - local _dwcall=_rc - if (`_dwcall'!=0){ - cap datalibweb, country(`natcode') year(`year') vera(WRK) verm(`gpwg_wm') type(gmd) mod(all) clear - local _dwcall=_rc - } - if (`_dwcall'!=0){ - dis as error "I was unable to call: datalibweb, country(`natcode') year(`years') vera(WRK) verm(`gpwg_wm') type(gmd) mod(gpwg) clear" - error 356781 - exit - } - else{ - cap isid hhid - if (_rc==0) sort hhid - else{ - cap sort hhid pid - if _rc!=0 sort hhid - } - cap recast float weight, force - cap recast float welfare, force - - - tempfile tocmp - save `tocmp' - } - restore - - cap recast float weight, force - cap recast float welfare, force - - - cap cf welfare weight using `tocmp', verbose - local cfrc = _rc - if `cfrc'==0{ - if (("`reg'"=="LAC" | (inlist("`natcode'","BGD","LKA","PAK","BTN","MDV","IND")==1)) & `=date(c(current_date),"DMY")'< `=date("28 Feb 2018","DMY")'){ - dis as error "Your new vintage does not update welfare or weights, but for LAC we will allow it...for now" - local gotoprimus = 1 - return local toprimus = 1 - } - else{ - dis as error "Your new vintage does not update welfare or weights, data will not be uploaded through Primus" - local gotoprimus = 0 - return local toprimus = 0 - } - - } - else{ - noi: display in y "Your new vintage updates welfare or weights, data will be uploaded through Primus" - local gotoprimus = 1 - } - } - - } - else{ - local gotoprimus = 1 - } -} -else{ //WHEN HH LEVEL COMPARISON IS REQUESTED - if (`newy'==0){ - if ("`gpwg_wm'"==""){ - preserve - cap datalibweb, country(`natcode') year(`year') vera(`gpwg_a') verm(`gpwg_m') type(gmd) mod(gpwg) clear - local _dwcall=_rc - if (`_dwcall'!=0){ - dis as error "I was unable to call: datalibweb, country(`natcode') year(`years') vera(`gpwg_a') verm(`gpwg_m') type(gmd) type(gpwg) clear " - error 356782 - exit - } - else{ - groupfunction, first(welfare) rawsum(weight) by(hhid) - cap recast float weight, force - cap recast float welfare, force - tempfile tocmp - save `tocmp' - } - restore - - preserve - groupfunction, first(welfare) rawsum(weight) by(hhid) - cap recast float weight, force - cap recast float welfare, force - cap cf welfare weight using `tocmp', verbose - local cfrc = _rc - if `cfrc'==0{ - local gotoprimus = 0 - dis as error "Your new vintage does not update welfare or weights, data will not be uploaded through Primus" - } - else{ - noi: display in y "Your new vintage updates welfare or weights, data will be uploaded through Primus" - local gotoprimus = 1 - } - restore - } - - } - else{ //compare to WRK version - preserve - cap datalibweb, country(`natcode') year(`years') vera(WRK) verm(`gpwg_wm') type(gmd) mod(gpwg) clear - local _dwcall=_rc - if (`_dwcall'!=0){ - cap datalibweb, country(`natcode') year(`years') vera(WRK) verm(`gpwg_wm') type(gmd) mod(all) clear - local _dwcall=_rc - } - if (`_dwcall'!=0){ - dis as error "I was unable to call: datalibweb, country(`natcode') year(`years') vera(WRK) verm(`gpwg_wm') type(gmd) mod(gpwg) clear" - error 356783 - exit - } - else{ - groupfunction, first(welfare) rawsum(weight) by(hhid) - cap recast float weight, force - cap recast float welfare, force - tempfile tocmp - save `tocmp' - } - restore - - preserve - groupfunction, first(welfare) rawsum(weight) by(hhid) - cap recast float weight, force - cap recast float welfare, force - cap cf welfare weight using `tocmp', verbose - local cfrc = _rc - if `cfrc'==0{ - if (("`reg'"=="LAC" | (inlist("`natcode'","BGD","LKA","PAK","BTN","MDV","IND")==1)) & `=date(c(current_date),"DMY")'< `=date("28 Feb 2018","DMY")'){ - dis as error "Your new vintage does not update welfare or weights, but for LAC we will allow it...for now" - local gotoprimus = 1 - return local toprimus = 1 - } - else{ - dis as error "Your new vintage does not update welfare or weights, data will no be uploaded through Primus" - local gotoprimus = 0 - return local toprimus = 0 - } - - } - else{ - noi: display in y "Your new vintage updates welfare or weights, data will be uploaded through Primus" - local gotoprimus = 1 - } - - restore - } - else{ - local gotoprimus = 1 - } -} - -return local gotoprimus=`gotoprimus' - -end - -program define MyPriCeData, rclass -version 11.2 -syntax, code(string) year(numlist max=1) survey(string) [datalevel(string)] - -cap datalibweb, country(support) year(2005) type(gmdraw) filename(Survey_price_framework.dta) surveyid(Support_2005_CPI_v04_M) -if _rc!=0{ - dis as error "Unable to load Survey_price_framework.dta" - error 123454 - exit -} - -keep if upper(code)==upper("`code'") & year==`year' & upper(survname)==upper("`survey'") - -if _N!=0{ - if (inlist(upper("`code'"), "CHN", "IDN", "IND")==1){ - if (inlist(upper("`datalevel'"), "N", "U", "R")!=1){ - dis as error "You must specify datalevel for `code'" - error 12938478 - exit - } - else{ - keep if upper(survey_coverage)==upper("`datalevel'") - if _N==1{ - local pricevars - foreach x of varlist *{ - levelsof `x', local(`x') - local pricevars `pricevars' `x' - } - - return local _pricevars `pricevars' - foreach x of local pricevars{ - return local _`x' ``x'' - } - } - else{ - dis as error "There is a problem in with the Survey price data, it is not unique" - dis as error "Reach out to central team" - error 344555 - exit - } - } - } - else{ - if _N==1{ - local pricevars - foreach x of varlist *{ - levelsof `x', local(`x') - local pricevars `pricevars' `x' - } - - return local _pricevars `pricevars' - foreach x of local pricevars{ - return local _`x' ``x'' - } - } - else{ - dis as error "There is a problem in with the Survey price data, it is not unique" - dis as error "Reach out to central team" - error 344555 - exit - } - } - -} -else{ - dis as error "There is no survey price data for your code, year, and survey combination" - dis as error "You must submit your data through the survey_price_framework" - error 4534545 - exit -} -end +*! primus_up.ado +*! December 2019 + +cap program drop primus_up +cap set matastrict off +program define primus_up, eclass + version 11.2 + syntax, /// + output(string) /// + NATcode(string) /// + YEARs(numlist >1900 min=1) /// + refyear(string) /// + WEFlist(varlist max=1) /// + VERMast_p(string) /// + VERAlt_p(string) /// + SURveys(string) /// + FILEname(string) /// + reg(string) /// + ctryname(string) /// + no_pweight(numlist max=1) /// + povweight(varname) /// + filename(string) /// + nopovcal(numlist max=1) /// + collection(string) /// + [SURVName(string) cpimethod(string) filepath(string) hhlev(integer 0) byvar(varname)] + +//Declare locals +local date1 = c(current_date) +local date2 : subinstr local date1 ":" "_", all +global output ="`output'" +global file0 ="primus_`date2'" +global dd ="uploading" +local aa 1 +local ccounT = "`natcode'" +local fname = "`filename'" + +tokenize `surveys', parse(_) +local mysvynm `5' +local mysvyY `3' +local myVM `7' +local myVA `11' + +//Ensure always sorted +cap isid hhid +local itis = _rc +if (`itis'==0) sort hhid +else sort hhid pid + +if ("`cpimethod'"=="") local method CustomCPI + +if (`no_pweight'==1 & `itis'!=0){ +// If the data is HH level and the user did not provide a weight, then by default +// weight_p and weight_i will be equal, thus no check is required. The check is only +// necessary iff you have individual level data and you did not provide a povweight + preserve + + tempvar popw povw + egen double `povw' = sum(weight_p*(weight_h!=. & hsize!=.)), by(hhid) + gen double `popw' = weight_h*hsize + + count if abs(`povw' - `popw')>0.01 & `povw'!=. & `popw'!=. + local dif = r(N) + if (`dif'>0){ + display as error "You need to specify weights to ensure replication of poverty at the individual and household level" + error 100 + exit + } + restore +} + +//To ensure old codes run +rename weight_p weight + + + +// Check what versions to compare to: +preserve +primus_vintage, country(`natcode') year(`years') wrk svy(`mysvynm') +local gpwg_wm = r(gpwg_wm) + local gpwg_wm = subinstr("`gpwg_wm'", ".","",.) +local gpwg_m = r(gpwg_m) + local gpwg_m = subinstr("`gpwg_m'", ".","",.) +local gpwg_a = r(gpwg_a) + local gpwg_a = subinstr("`gpwg_a'", ".","",.) +local newy = r(newy) +restore + +// Check to verify if Working Version has to be compared + +if ("`gpwg_wm'"!=""){ + //need natcode years surveys + preserve + qui: cap primus_query, country(`natcode') year(`years') + local qwrk = _rc==0 + if (`qwrk'==1){ + keep if regexm(survey_id,"`surveys'")==1 + keep if trim(lower(overall_status))=="pending" & trim(lower(uploader))=="true" + *set trace on + *set traced 1 + if (_N==0) local donotcompare = 1 + else{ + split survey_id, parse(_) + keep if trim(upper(survey_id4))==upper("`vermast_p'") & /// + upper(survey_id6)==upper("`veralt_p'") & (trim(lower(regional))=="pending"|trim(lower(uploader))=="false") + if (_N!=0){ + egen double maxdate =max(date_modified) + levelsof transaction_id if maxdate==date_modified, local(_tid) + + capture window stopbox rusure "Do you want to clear transid `_tid' from memory?" /// + "`filename'" + local stwrk = _rc==0 + + if (`stwrk'==1){ + primus_action, tranxid(`_tid') comments("Cancelled by `c(username)' through Primus upload process") /// + decision("REJECTED") + local donotcompare=1 + } + else{ + dis as error "You may not overwrite data with pending transaction id's" + error 238374 + exit + } + } + else local donotcompare = 0 + } + } + else{ + display as error "Unable to load query data, please try again" + error 3949444 + exit + } + restore +} +else{ +//verify older vintages + preserve + qui: cap primus_query, country(`natcode') year(`years') + local qwrk = _rc==0 + if (`qwrk'==1){ + if _N!=0{ + keep if regexm(lower(survey_id),lower("`mysvynm'"))==1 + egen double maxdate =max(date_modified) + drop if maxdate < `=clock("1 Jan 2018 00:00:00","DMY hms")' + + if (_N==0) local donotcompare = 0 + else{ + levelsof transaction_id if lower(survey_id)==lower("`surveys'") & lower(uploader)=="false" & lower(overall_status)=="pending", local(mytrans) + foreach id of local mytrans{ + primus_action, tranxid(`id') comments("Cancelled by `c(username)' through Primus upload process") /// + decision("REJECTED") + } + + if (_N==0) local donotcompare = 1 + else local donotcompare = 0 + + } + } + else local donotcompare = 1 + } + else{ + display as error "Unable to load query data, please try again" + error 3949444 + exit + } + restore +} //END ELSE + +//Compare data to previous vintages, or current working versions!! +if ("`collection'"=="GMD"){ + if (`donotcompare'==0){ + noi:primuSCompaRe, newy(`newy') natcode(`natcode') year(`years') gpwg_a(`gpwg_a') gpwg_m(`gpwg_m') gpwg_wm(`gpwg_wm') hhlev(`hhlev') reg(`reg') + local gotoprimus=r(gotoprimus) + } + else local gotoprimus = 1 +} +else{ + local gotoprimus=1 +} + + +//Keep only one weight type if GPWG + if (regexm("`filename'","GPWG")==1){ + cap drop weight_h + cap rename weight_p weight + local theW weight + } + else{ + cap rename weight weight_p + local theW weight_p + } + + if ("`gotoprimus'"!="1" & `nopovcal'!=1){ + dis as error "You have not specified the nopovcal option, and thus data will not be submitted for confirmation" + error 29024 + exit + } + + if ("`gotoprimus'"=="1" & `nopovcal'==1){ + dis as error "Your data needs to be uploaded to povcalnet and trigger a transaction ID" + error 2929292 + exit + } + + local ccc `natcode' + local yyy `years' + di in red "`ccc':`yyy':`surveys':`vermast_p':`veralt_p'" + + tempfile MuDAta + save `MuDAta' + +//Price database! + qui datalibweb, country(Support) year(2005) type(GMDRAW) surveyid(Support_2005_CPI_v04_M) filename(Final_CPI_PPP_to_be_used.dta) clear + di r(cmdline) + local priceproblem=_rc + if (`priceproblem'==111|`priceproblem'==0){ + cap keep if upper(code)==upper("`ccc'") + if (_rc) keep if upper(countrycode)==upper("`ccc'") + tempfile cpi_ + save `cpi_' + } + else{ + dis as error "Unable to load price database" + error 128384 + exit + } + + use `MuDAta', clear + +//Datalevel + if ("`=upper("`ccc'")'"=="IDN" | "`=upper("`ccc'")'"=="CHN" | "`=upper("`ccc'")'"=="IND"){ + gen datalevel = 1 + local method EmbeddedCPI + } + else { + gen datalevel = 2 + } + +//Merge CPI + cap gen code = "`=upper("`ccc'")'" + cap drop cpi* + cap drop icp* + + if (strpos("`surveys'","EU-SILC")>0 | strpos("`surveys'","SILC")>0) replace year = year - 1 + + cap drop region + ren survey survname + qui merge m:1 code year datalevel survname using `cpi_', gen(_mcpi) keepus(region countryname ref_year cpi2011 icp2011) + ren survname survey + + * Display error if CPI data cannot be merged into the dataset being uploaded + *ta _mcpi + qui count if _mcpi==1 //Count observations that could not be merged with CPI data + if r(N) !=0{ + dis as error "Your survey could not be fully merged with CPI data. Please contact the Central Team and review Final_CPI_PPP_to_be_used.dta." + error 12345 + } + * qui merge m:1 code year datalevel using `cpi_', gen(_mcpi) keepus(region countryname ref_year cpi2011 icp2011) //SM19 code + + qui drop if _mcpi==2 + qui drop _mcpi + cap drop datalevel + cap drop ppp_note + +//define deflators + local cpi cpi2011 + local ppp icp2011 + if (strpos("`surveys'","EU-SILC")>0 | strpos("`surveys'","SILC")>0) replace year = year + 1 + + local refyr = `refyear' + if ("`refyr'"=="."|strpos("`surveys'","SILC")>0){ + if (strpos("`surveys'","EU-SILC")>0 | strpos("`surveys'","SILC-C")>0) local refyr `=`yyy'-1' + else local refyr `yyy' + } + +tempfile dataout +save `dataout',replace +cap log close logall + + + ***************************** XML *************************** + //Prepare the files and naming structures. + local date = c(current_date) + local time = c(current_time) + local datetime `date' `time' + + //Indicator calculation - XML + tempfile xmlout logfile + log using "`logfile'", text replace name(logall) + + //Setup for XML + //local byvar + local countrycode `ccc' + local pppyear 2011 + local surveyid `surveys' + local filename `fname' + local year `yyy' + + + if "`weflist'"=="" local weflist welfare + if "`weightlist'"=="" local weightlist `theW' + if "`pppyear'"=="" local pppyear 2011 + if "`plines'"=="" { + if `pppyear'==2011 local plines 1.9 3.2 + if `pppyear'==2005 local plines 1.25 2.0 + } + + + log off logall + + //new values + dis %10.0g + levelsof `cpi', local(newCPIValue) + levelsof `ppp', local(newPPPValue) + + local cpilist `newCPIValue' + local icplist `newPPPValue' + + display in red "`icplist'" + display in red "`cpilist'" + //adjust local + local weflist = trim("`weflist'") + local weflist1 : subinstr local weflist "`=char(32)'" ",", all + local weightlist = trim("`weightlist'") + if (`: word count `weightlist''>1) & (`: word count `weflist''>1) & (`: word count `weightlist'' < `: word count `weflist'') { + dis in red "No balanced pairs of welfare and weight variables" + exit 198 + } + if (`: word count `weightlist''==1) & (`: word count `weflist''>1) { + local weightlist = "`weightlist' " * `: word count `weflist'' + } + + local weightlist = trim("`weightlist'") + local weightlist1 : subinstr local weightlist "`=char(32)'" ",", all + + local wset + forv j=1(1)`: word count `weflist'' { + local wf : word `j' of `weflist' + local wt : word `j' of `weightlist' + local wset "`wset' `wf'|`wt'" + } + local wset = trim("`wset'") + local wset : subinstr local wset "`=char(32)'" ",", all + + //reload the data + use `dataout', clear + + //byvar check + if "`byvar'"~="" { + ta `byvar' + local nbyvar = r(r) + local byvar2 `byvar' + } + else { + local nbyvar 1 + gen __all__ = 1 + la def __all__ 1 "All sample" + la val __all__ __all__ + local byvar2 __all__ + } + + //count number of requests + local nwevar : word count `weflist' + local nwivar : word count `weightlist' + local npline : word count `plines' + local nParamSets = `npline' + + local paset + foreach vicp of local icplist{ + foreach vcpi of local cpilist{ + foreach pline of local plines{ + if "`method'"=="CustomCPI" local paset "`paset'&Param=Method=`method'|PL=`pline'|PPP=`vicp'|CPI=`vcpi'" + if "`method'"=="EmbeddedCPI" local paset "`paset'&Param=Method=`method'|PL=`pline'" + } + } + } + display in yellow "`paset'" + + //invalid group results can be written as "n/a" + log on logall + + local RequestKey task=Povcal&DataSource=InboundDTA&CountryCode=`countrycode'&DataYear=`year'&By=`byvar'&BaseYear=`pppyear'&welfareSet=`wset'`paset' + dis in yellow "`RequestKey'" + local APP_ID Stata + local DATETIME `datetime' + local IS_INTERPOLATED FALSE + local USE_MICRODATA TRUE + //UNIT_OBS: HH or IND + local UNIT_OBS + local COUNTRY_CODE `countrycode' + local COUNTRY_NAME `ctryname' + local SURVEY_ID `surveyid' + local FILENAME `filename' + local REGION_CODE `reg' + local DATA_COVERAGE 3 + local DATA_TYPE 0 + local DATA_YEAR `year' + local REF_YEAR `refyr' + local CPI_YEAR `refyr' + local PPP_YEAR `pppyear' + log off logall + + //PRIMUS log + tempfile outdata + tempname outfile + file open `outfile' using "`outdata'", read write text + file write `outfile' `""' _n + file write `outfile' _col(2) `""' _n + file write `outfile' _col(4) `""' _n + file write `outfile' _col(4) `"`weflist1'"' _n + file write `outfile' _col(4) `"`weightlist1'"' _n + file write `outfile' _col(4) `"`byvar'"' _n + file write `outfile' _col(4) `"`nbyvar'"' _n + file write `outfile' _col(4) `"`nParamSets'"' _n + file write `outfile' _col(4) `""' _n + file write `outfile' _col(2) `""' _n + file write `outfile' _col(2) `""' _n + + //List of important Char + char _dta[uploaddate] `DATETIME' + char _dta[filename] `FILENAME' + char _dta[survey_id] `SURVEY_ID' + char _dta[use_microdata] `USE_MICRODATA' + char _dta[unit_observation] `UNIT_OBS' + char _dta[ref_year] `refyr' + char _dta[data_year] `DATA_YEAR' + + //Chars for priceframework + + preserve + tokenize `surveys', parse(_) + local _milhouse `5' + if (inlist(upper("`code'"), "CHN", "IDN", "IND")==1) MyPriCeData, code(`natcode') year(`years') survey(`_milhouse') datalevel(N) + else MyPriCeData, code(`natcode') year(`years') survey(`_milhouse') + + restore + + local pricevars `r(_pricevars)' + foreach price of local pricevars{ + char _dta[`price'] `r(_`price')' + } + + + tempfile data0 + save `data0', replace + + log off logall + local j = 1 + + foreach var of local weflist { + use `data0', clear + local wt : word `j' of `weightlist' + //welfare and weight + file write `outfile' _col(4) `""' _n + log on logall + + //Byvar + dis "//Type the below to call your data only if it has already been confirmed and approved" + dis "datalibweb, country(`ccc') year(`yyy') vera(`veralt_p') verm(`vermast_p') type(`collection') module(gpwg) clear" + dis "//Type the below to call your data if it has only been confirmed, but not approved" + dis "datalibweb, country(`ccc') year(`yyy') vera(WRK) verm(`vermast_p') type(`collection') module (gpwg) clear" + dis "gen double `var'_PPP = `var'/ `cpi' / `icp' /365" + dis "su `var' [aw=`wt']" + su `var' [aw=`wt'] + local TotalPopAll = `=r(sum_w)'/1000000 + levelsof `byvar2', local(bylist) + foreach byv of local bylist { + use `data0', clear + keep if `byvar2'==`byv' + tempfile data2 + save `data2', replace + + //data summary + su `var' [aw=`wt'] + local nRecs = r(N) + local TotalPopulation = `=r(sum_w)'/1000000 + local Mean_LCU = r(mean) + local TotalWealth_LCU = r(sum) + local Min_LCU = r(min) + local Max_LCU = r(max) + dis "ainequal `var' [aw=`wt'], all" + noi:ainequal `var' [aw=`wt'],all + local Gini = 100*`=r(gini_1)' + local MLD = 100*`=r(mld_1)' + *local PPPadjuster 1 + sort `var' + _ebin `var' [fw=`wt'], gen(deciles) nq(10) + gen double a = `var'*`wt' + collapse (sum) a, by(deciles) + egen double all = total(a) + gen double share = a/all + sort deciles + forv i=1(1)10 { + local Decile`i' = 100*share[`i'] + } + + log off logall + //byCondition - when there is nothing NULL + //write PRIMUS LOG - bygroup + if "`byvar2'"=="__all__" file write `outfile' _col(4) `""' _n + else file write `outfile' _col(4) `""' _n + file write `outfile' _col(6) `""' _n + file write `outfile' _col(8) `""' _n + file write `outfile' _col(6) `""' _n + + //calculation on poverty + //repeat as needed (different CPI/PPP and povlines) + //forv j=1(1)`nParamSets' { + if "`method'"=="CustomCPI" { //CustomCPI on the query + foreach vicp of local icplist { + foreach vcpi of local cpilist { + foreach pline of local plines { + use `data2', clear + //gen `var'_PPP = `var'/cpi`pppyear'/icp`pppyear'/365 + gen double `var'_PPP = `var'/`vcpi'/`vicp'/365 + local METHOD "`method'" + local PPPValue = `vicp' + local CPIValue = `vcpi' + su `var'_PPP [aw=`wt'] + local ReqYearPopulation = `=r(sum_w)'/1000000 + local MeanPPP = r(mean) + local PovertyLine_LCU = `=`pline'*`PPPValue'*`CPIValue'' + local PovertyLine_PPP = `pline' + local PPPadjuster = `PPPValue'*`CPIValue' + local ByVarShare = (`ReqYearPopulation'/`TotalPopAll')*100 + + log on logall + dis "apoverty `var'_PPP [aw=`wt'], line(`pline') all" + noi: apoverty `var'_PPP [aw=`wt'], line(`pline') all + local Headcount = `=r(head_1)' + local PovertyGap = `=r(pogapr_1)' + local PovertyGapSquared = `=r(fogto3_1)' + local Watt = `=r(watts_1)' + local Npoor = (`Headcount'*`ReqYearPopulation')/100 + log off logall + + //calculation log + file write `outfile' _col(6) `""' _n + file write `outfile' _col(8) `""' _n + file write `outfile' _col(6) `""' _n + } // nparamset pline + } + } + } + if "`method'"=="EmbeddedCPI" { //CPI PPP in the data + foreach pline of local plines { + use `data2', clear + //check tosee if CPI and PPP are constant within groups + qui su `cpi' + if r(sd) ~= 0 { + dis as error "CPI values should be constant within a group - `byvar2'==`byv'" + error 198 + } + qui su `ppp' + if r(sd) ~= 0 { + dis as error "ICP/PPP values should be constant within a group - `byvar2'==`byv'" + error 198 + } + gen `var'_PPP = `var'/ `cpi' / `ppp' /365 + //gen `var'_PPP = `var'/`cpi'/`icp'/365 + local METHOD "`method'" + local PPPValue = `icp'[1] + local CPIValue = `cpi'[1] + + noi dis in yellow "`CPIValue'" + su `var'_PPP [aw=`wt'] + local ReqYearPopulation = `=r(sum_w)'/1000000 + local MeanPPP = r(mean) + local PovertyLine_LCU = `=`pline'*`PPPValue'*`CPIValue'' + local PovertyLine_PPP = `pline' + local PPPadjuster = `PPPValue'*`CPIValue' + local ByVarShare = (`ReqYearPopulation'/`TotalPopAll')*100 + + log on logall + dis "apoverty `var'_PPP [aw=`wt'], line(`pline') all" + noi:apoverty `var'_PPP [aw=`wt'], line(`pline') all + local Headcount = `=r(head_1)' + local PovertyGap = `=r(pogapr_1)' + local PovertyGapSquared = `=r(fogto3_1)' + local Watt = `=r(watts_1)' + local Npoor = (`Headcount'*`ReqYearPopulation')/100 + log off logall + + //calculation log + file write `outfile' _col(6) `""' _n + file write `outfile' _col(8) `""' _n + file write `outfile' _col(6) `""' _n + } // nparamset pline + } + file write `outfile' _col(4) `""' _n + } //byvar + log off logall + file write `outfile' _col(4) `""' _n + local j = `j' + 1 + } //welfare + + + //end + file write `outfile' _col(2) `""' _n + log close logall + + //LOG Detail code + clear + qui set obs 1 + tempname note docout mystr + file write `outfile' _col(2) `""' _n + file write `outfile' _col(8) `""' _n + file write `outfile' _col(2) `""' _n + file write `outfile' `""' + file close `outfile' + qui capture copy "`outdata'" "`xmlout'", replace + if _rc { + display as error "file can not be saved at this location" + exit 603 + } + else { + noi display in yellow "XML File saved in: `xmlout'" + } + + + //Compress the file + use `data0', clear + cap drop __0* + cap drop __all__ + if "`method'"=="CustomCPI" local vlist min max cpi ppp cpi2005 icp2005 icp2011 cpi2011 icpbase cpiy conversion ipc05_sedlac ipc_sedlac filename suryear1 suryear2 weightcheck weightcheck2 update upldatetime username year_adj year_alt datasignature lvlvalue lvlvar + if "`method'"=="EmbeddedCPI" local vlist min max cpi ppp cpiy conversion ipc05_sedlac ipc_sedlac filename suryear1 suryear2 weightcheck weightcheck2 update upldatetime username year_adj year_alt datasignature lvlvalue lvlvar + foreach var of local vlist { + cap drop `var' + } + cap ren subnatid1 subnatid + cap drop region + + //need to add in the SurveyID, filename, data level (hh or ind), micro vs grouped, data date + + //Variabels go into characteristics + local constantlist weighttype welfaretype welfshprtype weighttype survey vermast veralt harmonization cpiperiod level ref_year + foreach var of local constantlist { + cap des `var' + if _rc==0 { + //check if the variables are really constant + cap confirm numeric variable `var' + if _rc==0 { + qui su `var' + if r(sd)==0 { + char _dta[`var'] `=`var'[1]' + cap drop `var' + } + } + else { //string + qui ta `var' + if r(r)==1 { + char _dta[`var'] `=`var'[1]' + cap drop `var' + } + } + } + } + + compress + cap drop cpi* + cap drop icp* + cap datasignature set + if (_rc!=0) datasignature set, reset + saveold `dataout', replace + + copy `xmlout' "C:\Users\\`c(username)'\\Downloads\_XML", replace + if (`nopovcal'==0){ + if (`gotoprimus'==1){ + //Send the file and log + //set trace on + tempfile resultfile + local plusdir "`c(sysdir_plus)'" + cap program define _primus, plugin using("`plusdir'\p\Primus`=cond(strpos(`"`=c(machine_type)'"',"64"),64,32)'.dll") + cap plugin call _primus , "0" "`xmlout'" "`dataout'" "`surveyid'" "`resultfile'" "3" + if _rc==0 { + ereturn local transid "`primusTxId'" + insheet using "`resultfile'", noname clear + noi dis + loc ++aa + qui putexcel A`aa'=("`surveys'") B`aa'=("Uploaded") + noi:display in yellow "PRIMUS YES:`ccc':`yyy'" + + } + else { + noi: display as error "Unable to upload data to system" + loc ++aa + qui putexcel A`aa'=("`surveys'") B`aa'=("Not uploaded") + noi: display in yellow "NO:`ccc':`yyy'" + error 233093 + } + } + } + else{ + + saveold "`filepath'//`filename'", replace + display as error "Your data has been saved to: " + display as error "`filepath'/`filename' " + display as error "Please inform the Central Team (mnguyen3@worldbank.org) about this upload." + } + + +end + + +program define primuSCompaRe, rclass +version 11.2 +syntax, [newy(numlist) natcode(string) year(numlist) reg(string) gpwg_a(string) gpwg_m(string) gpwg_wm(string) hhlev(integer 0)] + + +if (`hhlev'==0){ + if (`newy'==0){ + if ("`gpwg_wm'"==""){ + preserve + noi: dis in red "datalibweb, country(`natcode') year(`year') vera(`gpwg_a') verm(`gpwg_m') type(gmd) mod(gpwg) clear" + cap datalibweb, country(`natcode') year(`year') vera(`gpwg_a') verm(`gpwg_m') type(gmd) mod(gpwg) clear + local _dwcall=_rc + if (`_dwcall'!=0){ + dis as error "I was unable to call: datalibweb, country(`natcode') year(`years') vera(`gpwg_a') verm(`gpwg_m') type(gmd) type(gpwg) clear " + exit + } + else{ + cap isid hhid + if (_rc==0) sort hhid + else{ + cap sort hhid pid + if _rc!=0 sort hhid + } + cap recast float weight, force + cap recast float welfare, force + + tempfile tocmp + save `tocmp' + } + restore + + cap recast float weight, force + cap recast float welfare, force + + + cap cf welfare weight using `tocmp', verbose + local cfrc = _rc + if `cfrc'==0{ + local gotoprimus = 0 + dis as error "Your new vintage does not update welfare or weights, data will not be uploaded through Primus" + exit + } + else{ + noi: display in y "Your new vintage updates welfare or weights, data will be uploaded through Primus" + local gotoprimus = 1 + } + } + else{ //compare to WRK version + preserve + cap datalibweb, country(`natcode') year(`year') vera(WRK) verm(`gpwg_wm') type(gmd) mod(gpwg) clear + local _dwcall=_rc + if (`_dwcall'!=0){ + cap datalibweb, country(`natcode') year(`year') vera(WRK) verm(`gpwg_wm') type(gmd) mod(all) clear + local _dwcall=_rc + } + if (`_dwcall'!=0){ + dis as error "I was unable to call: datalibweb, country(`natcode') year(`years') vera(WRK) verm(`gpwg_wm') type(gmd) mod(gpwg) clear" + error 356781 + exit + } + else{ + cap isid hhid + if (_rc==0) sort hhid + else{ + cap sort hhid pid + if _rc!=0 sort hhid + } + cap recast float weight, force + cap recast float welfare, force + + + tempfile tocmp + save `tocmp' + } + restore + + cap recast float weight, force + cap recast float welfare, force + + + cap cf welfare weight using `tocmp', verbose + local cfrc = _rc + if `cfrc'==0{ + if (("`reg'"=="LAC" | (inlist("`natcode'","BGD","LKA","PAK","BTN","MDV","IND")==1)) & `=date(c(current_date),"DMY")'< `=date("28 Feb 2018","DMY")'){ + dis as error "Your new vintage does not update welfare or weights, but for LAC we will allow it...for now" + local gotoprimus = 1 + return local toprimus = 1 + } + else{ + dis as error "Your new vintage does not update welfare or weights, data will not be uploaded through Primus" + local gotoprimus = 0 + return local toprimus = 0 + } + + } + else{ + noi: display in y "Your new vintage updates welfare or weights, data will be uploaded through Primus" + local gotoprimus = 1 + } + } + + } + else{ + local gotoprimus = 1 + } +} +else{ //WHEN HH LEVEL COMPARISON IS REQUESTED + if (`newy'==0){ + if ("`gpwg_wm'"==""){ + preserve + cap datalibweb, country(`natcode') year(`year') vera(`gpwg_a') verm(`gpwg_m') type(gmd) mod(gpwg) clear + local _dwcall=_rc + if (`_dwcall'!=0){ + dis as error "I was unable to call: datalibweb, country(`natcode') year(`years') vera(`gpwg_a') verm(`gpwg_m') type(gmd) type(gpwg) clear " + error 356782 + exit + } + else{ + groupfunction, first(welfare) rawsum(weight) by(hhid) + cap recast float weight, force + cap recast float welfare, force + tempfile tocmp + save `tocmp' + } + restore + + preserve + groupfunction, first(welfare) rawsum(weight) by(hhid) + cap recast float weight, force + cap recast float welfare, force + cap cf welfare weight using `tocmp', verbose + local cfrc = _rc + if `cfrc'==0{ + local gotoprimus = 0 + dis as error "Your new vintage does not update welfare or weights, data will not be uploaded through Primus" + } + else{ + noi: display in y "Your new vintage updates welfare or weights, data will be uploaded through Primus" + local gotoprimus = 1 + } + restore + } + + } + else{ //compare to WRK version + preserve + cap datalibweb, country(`natcode') year(`years') vera(WRK) verm(`gpwg_wm') type(gmd) mod(gpwg) clear + local _dwcall=_rc + if (`_dwcall'!=0){ + cap datalibweb, country(`natcode') year(`years') vera(WRK) verm(`gpwg_wm') type(gmd) mod(all) clear + local _dwcall=_rc + } + if (`_dwcall'!=0){ + dis as error "I was unable to call: datalibweb, country(`natcode') year(`years') vera(WRK) verm(`gpwg_wm') type(gmd) mod(gpwg) clear" + error 356783 + exit + } + else{ + groupfunction, first(welfare) rawsum(weight) by(hhid) + cap recast float weight, force + cap recast float welfare, force + tempfile tocmp + save `tocmp' + } + restore + + preserve + groupfunction, first(welfare) rawsum(weight) by(hhid) + cap recast float weight, force + cap recast float welfare, force + cap cf welfare weight using `tocmp', verbose + local cfrc = _rc + if `cfrc'==0{ + if (("`reg'"=="LAC" | (inlist("`natcode'","BGD","LKA","PAK","BTN","MDV","IND")==1)) & `=date(c(current_date),"DMY")'< `=date("28 Feb 2018","DMY")'){ + dis as error "Your new vintage does not update welfare or weights, but for LAC we will allow it...for now" + local gotoprimus = 1 + return local toprimus = 1 + } + else{ + dis as error "Your new vintage does not update welfare or weights, data will no be uploaded through Primus" + local gotoprimus = 0 + return local toprimus = 0 + } + + } + else{ + noi: display in y "Your new vintage updates welfare or weights, data will be uploaded through Primus" + local gotoprimus = 1 + } + + restore + } + else{ + local gotoprimus = 1 + } +} + +return local gotoprimus=`gotoprimus' + +end + +program define MyPriCeData, rclass +version 11.2 +syntax, code(string) year(numlist max=1) survey(string) [datalevel(string)] + +cap datalibweb, country(support) year(2005) type(gmdraw) filename(Survey_price_framework.dta) surveyid(Support_2005_CPI_v04_M) +if _rc!=0{ + dis as error "Unable to load Survey_price_framework.dta" + error 123454 + exit +} + +keep if upper(code)==upper("`code'") & year==`year' & upper(survname)==upper("`survey'") + +if _N!=0{ + if (inlist(upper("`code'"), "CHN", "IDN", "IND")==1){ + if (inlist(upper("`datalevel'"), "N", "U", "R")!=1){ + dis as error "You must specify datalevel for `code'" + error 12938478 + exit + } + else{ + keep if upper(survey_coverage)==upper("`datalevel'") + if _N==1{ + local pricevars + foreach x of varlist *{ + levelsof `x', local(`x') + local pricevars `pricevars' `x' + } + + return local _pricevars `pricevars' + foreach x of local pricevars{ + return local _`x' ``x'' + } + } + else{ + dis as error "There is a problem in with the Survey price data, it is not unique" + dis as error "Reach out to central team" + error 344555 + exit + } + } + } + else{ + if _N==1{ + local pricevars + foreach x of varlist *{ + levelsof `x', local(`x') + local pricevars `pricevars' `x' + } + + return local _pricevars `pricevars' + foreach x of local pricevars{ + return local _`x' ``x'' + } + } + else{ + dis as error "There is a problem in with the Survey price data, it is not unique" + dis as error "Reach out to central team" + error 344555 + exit + } + } + +} +else{ + dis as error "There is no survey price data for your code, year, and survey combination" + dis as error "You must submit your data through the survey_price_framework" + error 4534545 + exit +} +end diff --git a/p/primus_upload.ado b/primus_upload.ado similarity index 97% rename from p/primus_upload.ado rename to primus_upload.ado index c535d04..fa77f82 100644 --- a/p/primus_upload.ado +++ b/primus_upload.ado @@ -1,1740 +1,1740 @@ -*! primus_upload.ado -*! Joao Pedro Azevedo, Raul Andres Castaneda, Paul Corral, Minh Cong Nguyen -*! December 2019 - -cap program drop primus_upload -program define primus_upload, rclass - - version 11.0 - - syntax [if] [in] , /// - Countrycode(string) /// - Year(numlist >1900 int max=1) /// - WELFare(varname) /// - welfaretype(string) /// - WELFSHprosperity(varname) /// - welfshprtype(string) /// - weight(varname) /// - weighttype(string) /// - HSize(varname) /// - hhid(varname) /// - MODule(string) /// - SURvey(string) /// - [ /// - cpi(varname) /// - CPIPERiod(string) /// - ppp(varname) /// - pid(varname) /// - collection(string) /// - POVWeight(varname) /// - drive(string) /// - SUBnatid1(varname) /// - spdef(varname) /// - Time(string) /// - welfarenom(varname) /// - welfaredef(varname) /// - welfareother(varname) /// - welfareothertype(string) /// - age(varname) /// - male(varname) /// - URBan(varname) /// - tfood(varname) /// - tnfood(varname) /// - rent(varname) /// - durgood(varname) /// - health(varname) /// - VERMast(string) /// - HARmonization(string) /// - VERAlt(string) /// - FULLname(string) /// - CONVERfactor(varname) /// - OTHERVARiables(varlist) /// - STRATa(varname) /// - psu(varname) /// - note(string) /// - SAVEPath(string) /// - ICPbase(integer 2011) /// - save13 /// - restricted /// - replace /// - NOPOVcal /// - level(varname) /// - output(string) /// - welfare_primus(string) /// - REFYear(string) /// - AUTOversion /// - OVERwrite /// - hhlev(integer 0) /// - ] -*=============================================================================== -//00:Keep Data; and necessary programs -*=============================================================================== -qui{ -if ("`keepdata'" != "") { - tempfile _tmp - save `_tmp', replace -} - -//Necessary ados -cap which lstrfun -if _rc ssc install lstrfun - -cap which mdesc -if _rc ssc install mdesc - -cap which confirmdir -if _rc ssc install confirmdir - - -*=============================================================================== -// 01:Error checks -*=============================================================================== -//Split fullname -if ("`fullname'"!=""){ - local fullname = trim(upper("`fullname'")) - - tokenize `fullname', parse("_") - local countrycode = "`1'" - local year = "`3'" - local survey = "`5" - local verm = subinstr("`7'","V","",.) - local vera = subinstr("`11'","V","",.) - local collection = "`15'" - if ("`17'"!="") local module = "`17'" - - local fullname -} -//Upper case all necessary inputs -local uppercase countrycode module survey harmonization collection vermast veralt /// -fullname welfaretype welfshprtype welfareothertype weighttype - - foreach x of local uppercase{ - if ("``x''"!="") local `x' = upper(trim("``x''")) - local remove1 `remove1' `x' - } - -//...Check for uniqueness, before anything! -if ("`pid'"==""){ -cap isid `hhid' - if (_rc!=0){ - dis as error "Data is not unique at `hhid' level, please revise" - error 459 - exit - } -} -else{ -cap isid `hhid' `pid' - if (_rc!=0){ - dis as error "Data is not unique at `hhid' and `pid' level, please revise" - error 459 - exit - } -} - -// Check if welfare and weights are double -foreach x of varlist `welfare' `weight' `povweight'{ - cap confirm existence `x' - if (_rc==0){ - * Examine precision of variables being uploaded - local thetype: type `x' - if ("`thetype'"!="double") & ("`nopovcal'"!=""){ //display error for nopovcal uploads, not dialog box - display as error "It is preferable that you upload variable `x' with double precision." - } - else { - capture window stopbox rusure "It is preferable that you upload variable `x' with double precision." /// - "Would you like to continue as is?" - local stwrk = _rc==0 - if (`stwrk'==0){ //If user selects "No" to the previous dialog box - dis as error "Variable `x' must be stored with double precision." - error 34567 - exit - } - } - - qui: sum `x' - if (r(mean) ==0){ - dis as error "Variable `x' has mean 0, this should not be the case" - error 198 - exit - } - } - else{ - dis as error "Variable `x' not found" - error 198 - exit - } -} - - - -//Remove vars from othervars -local othervariables : list othervariables - remove1 -local othervariables : list othervariables - welfare -local othervariables : list othervariables - weight -local othervariables : list othervariables - povweight - - - -//Collection -if ("`collection'"=="") local collection GMD -local collection =trim(upper("`collection'")) -if (inlist("`collection'", "GMD", "PCN")==0){ - dis as error "`collection' is not a valid collection, only GMD or PCN are accepted" - error 1203934 - exit -} - -//Specify module and ensure path is there -if ("`module'"==""){ - dis as error "You must specify a module, such as _ALL" - error 12734764 - exit -} -local modulelist ALL I2D2 GPWG -local _modch: list modulelist & module -if ("`_modch'"==""){ - dis as error "You have specified an unrecognized module" - error 1637344 - exit -} - -//Ensure excel file for file uploads is specified -if (trim(upper("`module'"))=="ALL"|trim(upper("`module'"))=="GPWG"){ - if ("`output'"==""){ - display as error "You must specify an excel file for storing upload details" - error 102939 - exit - } - else{ - local _dd=c(current_date) - putexcel set "`output'", sh("`_dd'", replace) modify - putexcel A1=("Unique_ID") B1=("Category") C1=("`_dd'") - } -} - -*=============================================================================== -// 02:Check for valid inputs -*=============================================================================== -local flagerr = 0 -//Country code checks -local countrycode = trim(upper("`countrycode'")) - if (length("`countrycode'")!=3){ - display as error "country code must be 3 digit iso country code" - local flagerr=1 - } - -local _thenats AFG ALB DZA ASM AND AGO ATG ARB ARG ARM ABW AUS AUT AZE BHS BHR /// -BGD BRB BLR BEL BLZ BEN BMU BTN BOL BIH BWA BRA BRN BGR BFA BDI KHM CMR CAN CPV /// -CSS CYM CAF CUW TCD CHI CHL CHN COL COM COD COG CRI CIV HRV CUB CUW CYP CZE DNK /// -DJI DMA DOM ECU EGY SLV GNQ ERI EST ETH EUU FRO FJI FIN FRA PYF GAB GMB GEO DEU /// -GHA GRC GRL GRD GUM GTM GIN GNB GUY HTI HND HKG HUN ISL IND IDN IRN IRQ IRL IMN /// -ISR ITA JAM JPN JOR KAZ KEN KIR PRK KOR KSV KWT KGZ LAO LVA LBN LSO LBR LBY LIE /// -LTU LUX MAC MKD MDG MWI MYS MDV MLI MLT MHL MRT MUS MEX FSM MDA MCO MNG MNE MAR /// -MOZ MMR NAM NPL NLD NCL NZL NIC NER NGA MNP NOR INX OED OMN OSS PSS PAK PLW PAN /// -PNG PRY PER PHL POL PRT PRI QAT ROU RUS RWA WSM SMR STP SAU SEN SRB SYC SLE SGP /// -SXM SVK SVN SST SLB SOM ZAF SSD ESP LKA KNA LCA MAF VCT SDN SUR SWZ SWE CHE SYR /// -TJK TZA THA TLS TGO TON TTO TUN TUR TKM TCA TUV UGA UKR ARE GBR USA URY UZB VUT /// -VEN VNM VIR PSE YEM ZMB ZWE SXM MAF - -local _natcheck: list _thenats & countrycode - -if ("`_natcheck'"==""){ - display as error "Country code not recognized, please provide a valid country code" - local flagerr=1 -} - -// Year -if length("`year'")!=4 { - noi di as err "year variable needs to be specified with four digits" - local flagerr = 1 -} - -//Check provided survey name is valid! -preserve -primus_vintage, country(`countrycode') svyname -local svnamestocheck = r(thesurveys) -local _aok: list survey & svnamestocheck -local _aok = "`_aok'"!="" -restore - - if (`_aok'==0){ - dis as error "The survey name provided does not exist, talk to central team" - error 3699 - exit - } - -//Welfare type -local flag2 = inlist("`welfaretype'", "INC", "CONS", "EXP") -if (`flag2' != 1) { - noi di as err "eligible welfare types: INC=INCOME; CONS=CONSUMPTION; EXP=EXPENDITURE" - local flagerr = 1 -} -//Welfare shared prosperity type -local flag2 = inlist("`welfshprtype'", "INC", "CONS", "EXP") -if (`flag2' != 1) { - noi di as err "eligible shared prosperity welfare types: INC=INCOME; CONS=CONSUMPTION; EXP=EXPENDITURE" - local flagerr = 1 -} -//Welfare other type! -if ("`welfareother'" != "") { - local flag2 = inlist("`welfareothertype'", "INC", "CONS", "EXP") - if (`flag2' != 1) { - noi di as err "eligible other welfare types: INC=INCOME; CONS=CONSUMPTION; EXP=EXPENDITURE" - local flagerr = 1 - } -} -//Weight type -local flag2 = inlist("`weighttype'", "FW", "PW", "AW", "IW") -if (`flag2' != 1) { - noi di as err "eligible weight types: FW=Frequency weights; PW=Probability weights; AW=Analytical weights; IW=Importance weights" - local flagerr = 1 -} -//Spatial Deflation -if ("`spdef'" != "" & "`subnatid1'" == ""){ - noi di as err "Spatial deflator can only be entered if data contain subnational ID. Please check." - local flagerr = 1 -} -*=============================================================================== -// 03:Program assigned inputs -*=============================================================================== -//Region codes -preserve - _countryname - levelsof region if countrycode=="`countrycode'", local(reg) clean - local good1: list sizeof reg - if (`good1'!=1){ - dis as error "Country code not assigned to a region" - local flagerr = 1 - } -restore -//Path Module -local pathmodule = "\\wbntst01.worldbank.org\TeamDisk\GPWG\datalib\all_region_primus\" - -//By var -local byvar `level' - -//Pov weight --> If missing -> Weight -if ("`povweight'"==""){ - local povweight `weight' - local no_pweight = 1 -} -else local no_pweight = 0 - -//Country name -preserve - _countryname - levelsof countryname if countrycode=="`countrycode'", local(primus_cname) -restore - -//Local with all variables in data -local varsindata -foreach x of varlist *{ - local varsindata `varsindata' `x' -} - -// If level is not specified -if "`level'"=="" { - cap drop _all_ - gen _all_ = 1 - local level2 _all_ -} -else { - gen temp = `level' - local level2 temp -} - -//Output -if ("`output'"==""){ - local output "c:\Users\\`c(username)'\Downloads\" -} - -//Weflare primus, if missing -if ("`welfare_primus'"=="") local welfare_primus welfare - -//Ref Year, if missing -if ("`refyear'"=="") local refyear = `year' - -*=============================================================================== -// 04:Version control -*=============================================================================== -//Autoversion - -if ("`autoversion'"!="" & "`collection'"=="GMD"){ -preserve - if (upper("`module'")=="GPWG" | upper("`module'")=="ALL") { - local nm = lower("`module'") - primus_vintage, country(`countrycode') year(`year') max svy(`survey') - - if ("`vermast'"=="") local vermast = "`r(maxm)'" - local veralt = "`r(maxa)'" - } - else{ - primus_vintage, country(`countrycode') year(`year') module(`module') - if ("`vermast'"=="") local vermast = "`r(newm)'" - local veralt = "`r(newa)'" - } -restore -} - - -//Version requirements once we have assigned these -if length("`vermast'")!=2 & "`fullname'" == ""{ - noi di as err "master version needs to have two digits" - local flagerr = 1 - local _vm=0 -} -else local _vm=1 - -if length("`veralt'")!=2 & "`fullname'" == ""{ - noi di as err "harmonization version needs to have two digits" - local flagerr = 1 - local _va=0 -} -else local _va = 1 - -//Check if vintages exists -if (`_vm'==1 & `_va'==1){ -preserve - primus_vintage, country(`countrycode') year(`year') svy(`survey') - local nm = lower(trim("`module'")) - local newyear=r(newy) - local _v_a = r(`nm'_a) - local _v_m = r(`nm'_m) - local _v_a = subinstr("`_v_a'", "V","",.) - local _v_a = subinstr("`_v_a'", ".","",.) - local _v_m = subinstr("`_v_m'", "V","",.) - local _v_m = subinstr("`_v_m'", ".","",.) -restore - if ("`_v_a'"=="`veralt'" & "`_v_m'"=="`vermast'" & "`newyear'"!="1"){ - if ("`overwrite'"==""){ - noi dis as error "You may not overwrite an existing vintage" - local docheck=0 - local flagerr = 1 - error 100000 - } - else local docheck=1 - } - else{ - local docheck = 0 - } -} - -//Full name and components -if ("`fullname'" == "") & (("`survey'" == "") | ("`vermast'" == "")) & (("`harmonization'" == "") | ("`veralt'" == "")){ - noi di as err "Either full name or name components have to be specified. Please check." - local flagerr = 1 -} - - -*=============================================================================== -// 6) Variables to be kept for collections, Select, rename, label Variables -// and value labels -*=============================================================================== - -if ("`collection'" == "GMD" & "`module'"=="GPWG") { - - local gpwgvars `welfare' `weight' `age' `male' `urban' `hhid' `hsize' `cpi' /// - `ppp' `strata' `psu' `time' `welfshprosperity' `othervariables' /// - `subnatid1' `spdef' `converfactor' `povweight' - local varstodrop: list varsindata - gpwgvars - if ("`varstodrop'" != "") noi disp in red _n "Caution: " in y /// - "the following variables in your dataset wont be included" /// - " in the `collection' collection:" _n _col(6) in w "`varstodrop'" - - keep `welfare' `weight' `age' `male' `urban' `hhid' `hsize' `cpi' /// - `ppp' `strata' `psu' `time' `welfshprosperity' `othervariables' /// - `subnatid1' `spdef' `converfactor' `povweight' `pid' -} - -if ("`collection'"=="PCN"){ - keep `hsize' `urban' `weight' `povweight' `hhid' `welfare' `cpi' `ppp' -} - - ************************************************** - /* select and rename variables */ - ************************************************** - - - cap clonevar pp_welfare =`welfare' - cap clonevar pp_welfarenom =`welfarenom' - cap clonevar pp_welfaredef =`welfaredef' - cap clonevar pp_welfareother =`welfareother' - cap clonevar pp_weight_h =`weight' - cap clonevar pp_weight_p =`povweight' - cap clonevar pp_age =`age' - cap clonevar pp_male =`male' - cap clonevar pp_urban =`urban' - cap clonevar pp_hsize =`hsize' - cap clonevar pp_hhid =`hhid' - cap clonevar pp_cpi =`cpi' - cap clonevar pp_ppp =`ppp' - cap clonevar pp_strata =`strata' - cap clonevar pp_psu =`psu' - cap clonevar pp_welfshprosperity =`welfshprosperity' - cap clonevar pp_subnatid1 =`subnatid1' - cap clonevar pp_spdef =`spdef' - cap clonevar pp_converfactor =`converfactor' - local myvardrop `welfare' `welfarenom' `welfaredef' `welfareother' /// - `weight' `age' `male' `urban' `hsize' `hhid' `cpi' /// - `ppp' `strata' `psu' `welfshprosperity' `subnatid1' /// - `spdef' `converfactor' - - foreach V of local myvardrop{ - cap drop `V' - } - cap drop `povweight' - renpfix pp_ - - cap drop countrycode - cap drop year - - cap gen countrycode = upper("`countrycode'") - cap gen year = `year' - cap gen welfaretype = upper("`welfaretype'") - cap gen welfshprtype = upper("`welfshprtype'") - - if ("`welfareothertype'" != "") { - cap gen welfareothertype = upper("`welfareothertype'") - } - - cap gen weighttype = upper("`weighttype'") - cap gen cpiperiod = "`cpiperiod'" - - - cap gen survey = "`survey'" - cap gen vermast = "`vermast'" - cap gen veralt = "`veralt'" - cap gen harmonization = "`harmonization'" - - * ICPbase - - if !inlist(`icpbase', 2005, 2011) { - noi disp in red "ICPbase variable must be either 2005 or 2011. Default 2011." - local flagerr = 1 - } - else { - cap gen icpbase = `icpbase' - label var icpbase "ICP reference year `icpbase'" - } - - ** other variables - if ("`age'" != "") | ("`male'" != "") { - local surveylevel "individual" - order countrycode year hhid welfaretype welfare //age male urban cpi* ppp weight - } - else { - local surveylevel "household" - order countrycode year hhid welfaretype welfare //urban cpi* ppp weight - } - - ************************************************** - /* label variables and values for GPWG databse */ - ************************************************** - - cap label var countrycode "WDI three letter country codes " - cap label var year "4 digit year of the survey" - cap label var spdef "Spatial deflator (if one is used)" - cap label var weight_h "Weight" - cap label var weight_p "Weight for poverty calculation" - cap label var weighttype "Weight type (frequency, probability, analytical, importance)" - cap label var cpi "CPI ratio value of survey (rebased to `icpbase' on base 1)" - cap label var cpiperiod "Periodicity of CPI (year, year&month, year&quarter, weighted)" - cap label var ppp "PPP conversion factor. (`icpbase')" - cap label var survey "Type of survey" - cap label var vermast "Version number of master data file" - cap label var veralt "Version number of adaptation to the master data file" - cap label var harmonization "Type of harmonization" - cap label var converfactor "Conversion factor" - cap label var subnatid1 "Subnational ID - highest level" - cap label var subnatid2 "Subnational ID - second highest level" - cap label var subnatid3 "Subnational ID - third highest level" - cap label var strata "Strata" - cap label var psu "PSU" - cap label var welfare "Welfare aggregate used for estimating international poverty (provided to PovcalNet)" - cap label var welfarenom "Welfare aggregate in nominal terms" - cap label var welfaredef "Welfare aggregate spatially deflated" - cap label var welfaretype "Type of welfare measure (income, consumption or expenditure) for welfare, welfarenom, welfaredef" - cap label var welfshprosperity "Welfare aggregate for shared prosperity (if different from poverty)" - cap label var welfshprtype "Welfare type for shared prosperity indicator (income, consumption or expenditure)" - cap label var welfareother "Welfare aggregate if different welfare type is used from welfare, welfarenom, welfaredef" - cap label var welfareothertype "Type of welfare measure (income, consumption or expenditure) for welfareother" - cap label var hsize "Household size" - cap label var hhid "Household ID" - - ************************************************** - /* Value labels values */ - ************************************************** - cap levelsof male, local(ckmale) - if regexm("0 1","`ckmale'") { - cap lab define male 1 Male 0 Female, modify - cap lab values male male - } - else { - if "`male'"!="" { - noi di as err "male variable [`male'] has values other than 0 and 1 (i.e. male=1, female=0), please check." - local flagerr = 1 - } - } - - cap levelsof urban, local(ckurban) - if regexm("0 1","`ckurban'") { - cap lab define urban 1 Urban 0 Rural, modify - cap lab values urban urban - } - else { - if "`urban'"!="" { - noi di as err "urban variable [`urban'] has values other than 0 and 1 (i.e. urban=1, rural=0), please check." - local flagerr = 1 - } - } - -*============================================================================== - //7: Variables Checks -*=============================================================================== -//GPWG Variable CHECKS -if (("`collection'" == "GMD"|"`collection'" == "PCN") & "`module'"=="GPWG"){ - local nums welfare weight age hsize - - foreach x of local nums{ - cap confirm var ``x'' - local is = _rc==0 - if (`is'==1){ - cap confirm numeric variable ``x'', exact - local is1 = _rc==0 - if (`is1'==0) local notnum `notnum' ``x'' - } - } - - if ("`notnum'"!="") { - dis as err "The following variables should be numeric:" /// - _n _col(6) in w "`notnum'" - local flagerr=1 - } - - if "`ppp'"!="" & "`countrycode'"!="IND" & "`countrycode'"!="IDN" & "`countrycode'"!="CHN"{ - qui sum ppp - - if (r(Var)>1e-6) { - noi di as err "PPP conversion factor is not constant within survey, please check." - local flagerr = 1 - } - } - - if ("`cpi'" != "" & "`countrycode'"!="IND" & "`countrycode'"!="IDN" & "`countrycode'"!="CHN") { - qui sum cpi - if (r(Var)>1e-6) { - noi di as err "CPI is not constant within survey, please specify period of reference variable." - local flagerr = 1 - } - } - - if ("`subnatid1'" != "") { - capture confirm string var subnatid1 - if (_rc) { - noi di as err "Subnatid1 was not correctly specified. Please, make sure that the following naming convention (string) is used: # – String" - local flagerr =1 - } - cap levelsof subnatid1, local(mysub) - local mysub: list sizeof mysub - if (`mysub'==1){ - noi dis as err "Subnatid1 is constant for all entries, please revise" - local flagerr =1 - } - - } - - - if ("`spdef'" != "") { - qui sum spdef - local var2spdef = r(Var) - if (`var2spdef' == 0) /*& (("`bypass'" != ""))*/ { - noi di as err "Spatial deflator is constant for all entries. Please check." - local flagerr = 1 - } - } - - /*household weights */ - if ("`weight'"!="" & "`countrycode'"!="PSE" & "`countrycode'"!="MAR") { - sort hhid - qui by hhid: egen double min=min(weight_h) - qui by hhid: egen double max=max(weight_h) - gen weightcheck2= min==max - qui: sum weightcheck2 - local wvalid = r(mean) - if `wvalid'!=0 { - noi di in red "Caution: "in y "Household weights are not unique within households. Please check." - } - drop min max weightcheck2 - } - - if ("`povweight'"!="" & "`countrycode'"!="PSE" & "`countrycode'"!="MAR") { - sort hhid - qui by hhid: egen double min=min(weight_p) - qui by hhid: egen double max=max(weight_p) - gen weightcheck2= min==max - qui: sum weightcheck2 - local wvalid = r(mean) - if `wvalid'!=0 { - noi di in red "Caution: "in y "Household weights for poverty are not unique within households. Please check." - } - drop min max weightcheck2 - } - -} - -//GMD Checks -if (trim(upper("`module'"))=="ALL" & "`collection'"=="GMD"){ - local checkvars spdef converfactor subnatid1 subnatid2 subnatid3 /// - strata psu welfarenom welfaredef welfshprosperity welfshprtype /// - welfareother welfareothertype pid agecat relationharm relationcs /// - marital lstatus minlaborage empstat industrycat10 industrycat4 school /// - literacy educy educat4 educat5 educat7 landphone cellphone computer /// - electricity primarycomp countrycode year welfaretype weighttype age /// - survey vermast veralt harmonization cpiperiod cpi ppp icpbase /// - imp_wat_rec imp_san_rec landphone cellphone computer electricity - - noi disp "" _n - - foreach checkvar of local checkvars { - cap confirm var `checkvar' - if _rc { - noi disp as err "Caution:" in y " variable" in w " `checkvar' " /// - in y "not found in dataset" - gen `checkvar' = . - local check`checkvar' = 0 - } - else { - local check`checkvar' = 1 - } - - } // end of checkvars loop - noi disp "" _n - - /*pid*/ - if (`checkpid' == 1 & !missing(pid)) { - sort countrycode year hhid pid - duplicates report countrycode year hhid pid - cap assert r(unique_value) == r(N) - if ("`pid'" != "") { - if _rc { - noi disp as err "variable pid is not unique for combination household/individual." /// - _n "{stata duplicates example countrycode year hhid pid: click here}" /// - " to see examples of duplicated obs." - local flagerr = 1 - } - } - } // end of pid - - //Subnat id checks...need to add shapefile codes - forval z=1/3{ - if (`checksubnatid`z''==1) { - capture confirm string var subnatid`z' - if (_rc) { - noi di as err "Subnatid`z' was not correctly specified. Please, make sure that the following naming convention (string) is used: # – String" - local flagerr =1 - } - cap levelsof subnatid`z', local(mysub) - local mysub1: list sizeof mysub - if (`mysub1'==1 & `"`mysub'"'!="`"."'"){ - noi dis as err "Subnatid`z' is constant for all entries, please revise" - local flagerr =1 - } - } - } - //relationharm - if (`checkrelationharm' == 1) { - cap assert missing(relationharm) - if _rc!=0{ - levelsof relationharm - if wordcount(r(levels)) > 6 { - noi disp as err "relationharm should not have more than 6 numeric values." /// - " It has " wordcount(r(levels)) " values" - local flagerr = 1 - } - - if wordcount(r(levels)) < 6 { - noi disp as err "Caution:" in y " relationharm has less than 6 values." /// - " It has " wordcount(r(levels)) " values" - } - - - ** check only one head per household - sort countrycode year hhid relationharm - tempvar nhh // number of head of the household - bysort hhid: egen `nhh' = total(relationharm == 1) - cap assert `nhh' == 1 | `nhh' == 0 - if _rc { - noi disp as err "There is more than one head per household. " /// - "Please check variable relationharm" - local flagerr = 1 - } - - ** check values - cap assert inrange(relationharm, 1,6) | relationharm == . - if _rc { - noi disp as err "relationharm should not have values outside the range {1,6}" - local flagerr = 1 - } - } - } - //Marital - if (`checkmarital' == 1) { - cap assert missing(marital) - if _rc!=0{ - levelsof marital - if wordcount(r(levels)) > 5 { - noi disp as err "marital should not have more than 5 numeric values." /// - " It has " wordcount(r(levels)) " values" - local flagerr = 1 - } - - cap if wordcount(r(levels)) < 5 { - noi disp as err "Caution:" in y " marital has less than 5 values." - } - - ** check values - cap assert inrange(marital, 1,5) | marital == . - if _rc { - noi disp as err "marital should not have values outside the range {1,5}" - local flagerr = 1 - } - } - } // end of Marital - - //lstatus - if (`checklstatus' == 1) { - cap assert missing(lstatus) - if _rc!=0{ - levelsof lstatus - if wordcount(r(levels)) > 3 { - noi disp as err "lstatus should not have more than 3 numeric values." /// - " It has " wordcount(r(levels)) " values" - local flagerr = 1 - } - ** check values - cap assert inrange(lstatus, 1,3) | lstatus == . - if _rc { - noi disp as err "lstatus should not have values outside the range {1,3}" - local flagerr = 1 - } - - if ("`lstatus'" != "" & "`minlaborage'" != "") { - count if (age < `minlaborage' & lstatus == 1) - if r(N) > 0 & r(N) < . { - noi disp as error "Caution:" in y " you have " in w r(N) in y /// - " underaged individuals (less than `minlaborage' years old) who are employed" - } - } - } - } - - /*empstat */ - if (`checkempstat' == 1) { - - cap assert missing(empstat) - if _rc!=0{ - levelsof empstat - if wordcount(r(levels)) > 5 { - noi disp as err "empstat should not have more than 5 numeric values." /// - " It has " wordcount(r(levels)) " values" - local flagerr = 1 - } - - if wordcount(r(levels)) < 5 { - noi disp as err "Caution:" in y" empstat has less than 5 values." - } - - ** check values - cap assert inrange(empstat, 1,5) | missing(empstat) - if _rc { - noi disp as err "empstat should not have values outside the range {1,5}" - local flagerr = 1 - } - - ** Consistency with other variables. - count if inlist(empstat,3,4) & age < minlaborage - if (r(N)>0 & r(N)<.) { - noi disp as err "Caution: " in y "There are " r(N) " underaged individuals (less than minlaborage) who" /// - " are either employers or self-employed. Please check if this is correct" - } - } - } - -/*industrycat10 */ - if (`checkindustrycat10' == 1) { - cap assert missing(industrycat10) - if _rc!=0{ - levelsof industrycat10 - if wordcount(r(levels)) > 10 { - noi disp as err "industrycat10 should not have more than 10 numeric values." /// - " It has " wordcount(r(levels)) " values" - local flagerr = 1 - } - } - } - -/*industrycat4 */ - if (`checkindustrycat4' == 1) { - cap assert missing(industrycat4) - if _rc!=0{ - levelsof industrycat4 - if wordcount(r(levels)) > 4 { - noi disp as err "industrycat4 should not have more than 4 numeric values." /// - " It has " wordcount(r(levels)) " values" - local flagerr = 1 - } - } - } - -/*school */ - if (`checkschool' == 1) { - cap assert missing(school) - if _rc!=0{ - cap assert inlist(school,0,1) | school == . - if _rc { - noi disp as err "variable school can only take either 0 or 1 as values. Please check" - } - } - } - -/*literacy */ - if (`checkliteracy' == 1) { - cap assert missing(literacy) - if _rc!=0{ - cap assert inlist(literacy,0,1) | literacy == . - if _rc { - noi disp as err "variable literacy can only take either 0 or 1 as values. Please check" - local flagerr = 1 - } - } - } - -/*educy */ - if (`checkeducy' == 1) { - cap assert missing(educy) - if _rc!=0{ - - count if (educy >= age & educy <. & educy != 0 ) - if (r(N)>0 & r(N)<.) { - noi disp as err "educy (years of education) cannot be greater or equal than age." /// - r(N) " Cases" - local flagerr = 1 - } - - count if ( age - educy <= 2 ) - if (r(N)>0 & r(N)<.) { - noi disp as err "Caution:" in y " For " r(N) " obs., educy (years of education) is" /// - " two or less years smaller than current age. Check if this is correct." - } - } - } - -/*educat4 */ - if (`checkeducat4' == 1) { - cap assert missing(educat4) - if _rc!=0{ - levelsof educat4 - if wordcount(r(levels)) > 4 { - noi disp as err "educat4 should not have more than 4 numeric values." /// - " It has " wordcount(r(levels)) " values" - local flagerr = 1 - } - } - } - -/*educat5 */ - if (`checkeducat5' == 1) { - cap assert missing(educat5) - if _rc!=0{ - levelsof educat5 - if wordcount(r(levels)) > 5 { - noi disp as err "educat5 should not have more than 5 numeric values." /// - " It has " wordcount(r(levels)) " values" - local flagerr = 1 - } - } - } - -/*educat7 */ - if (`checkeducat7' == 1) { - cap assert missing(educat7) - if _rc!=0{ - levelsof educat7 - if wordcount(r(levels)) > 7 { - noi disp as err "educat7 should not have more than 7 numeric values." /// - " It has " wordcount(r(levels)) " values" - local flagerr = 1 - } - } - } - -/*Assets */ - if (`checklandphone' == 1) { - cap assert missing(landphone) - if _rc!=0{ - cap assert inlist(landphone,0,1) | landphone == . - if _rc { - noi disp as err "asset can only take either 0 or 1 as values. Please check" - local flagerr = 1 - } - } - } - - if (`checkcellphone' == 1) { - cap assert missing(cellphone) - if _rc!=0{ - cap assert inlist(cellphone,0,1) | cellphone == . - if _rc { - noi disp as err "cellphone can only take either 0 or 1 as values. Please check" - local flagerr = 1 - } - } - } - - if (`checkcomputer' == 1) { - cap asser missing(computer) - if _rc!=0{ - cap assert inlist(computer,0,1) | computer == . - if _rc { - noi disp as err "computer can only take either 0 or 1 as values. Please check" - local flagerr = 1 - } - } - } - - if (`checkelectricity' == 1) { - cap assert missing(electricity) - if _rc!=0{ - cap assert inlist(electricity,0,1) | electricity == . - if _rc { - noi disp as err "electricity can only take either 0 or 1 as values. Please check" - local flagerr = 1 - } - } - } - -/* primarycomp */ - - if (`checkprimarycomp' == 1) { - cap assert missing(primarycomp) - if _rc!=0{ - cap assert inlist(primarycomp,0,1) | primarycomp == . - if _rc { - noi disp as err "primarycomp can only take either 0 or 1 as values. Please check" - local flagerr = 1 - } - } - } - -/* relationcs */ - - if (`checkrelationcs' == 1) { - * This is region specific... - } - -/* Age */ -* GMD 2.0 allows age to be a decimal for individuals <5 yrs - - if (`checkage' == 1) { - cap assert missing(age) - if _rc!=0{ - * integers for individuals older than 5 yrs - cap assert age == int(age) if age>5 - if _rc { - noi disp as err "age must be integers only for age >5 yrs. Please check!" - local flagerr = 1 - } - - cap assert age >= 0 // check age is positive or missing - if _rc { - noi disp as err "age cannot have negative values" - local flagerr = 1 - } - } - } - - -/* Survey */ - - if (`checksurvey' == 1 & !missing(survey)) { - cap assert missing(survey) - if _rc!=0{ - - cap assert regexm(survey,`"[a-zA-Z]+"') - if _rc { - noi disp as err "survey must contain only alphabetic values" - local flagerr = 1 - } - - } - } - - -/* Improved water */ - - if (`checkimp_wat_rec' == 1) { - cap assert missing(imp_wat_rec) - if _rc!=0{ - cap assert inlist(imp_wat_rec,0,1) | imp_wat_rec == . - if _rc { - noi disp as err "imp_wat_rec can only take either 0 or 1 as values. Please check!" - local flagerr = 1 - } - } - } - - -/* Improved sanitation */ - - if (`checkimp_san_rec' == 1) { - cap assert missing(imp_san_rec) - if _rc!=0{ - cap assert inlist(imp_san_rec,0,1) | imp_san_rec == . - if _rc { - noi disp as err "imp_san_rec can only take either 0 or 1 as values. Please check!" - local flagerr = 1 - } - } - } - -/* Landphone */ - - if (`checklandphone' == 1) { - cap assert missing(landphone) - if _rc!=0{ - cap assert inlist(landphone,0,1) | landphone == . - if _rc { - noi disp as err "landphone can only take either 0 or 1 as values. Please check!" - local flagerr = 1 - } - } - } - -/* Cell phone */ - - if (`checkcellphone' == 1) { - cap assert missing(cellphone) - if _rc!=0{ - cap assert inlist(cellphone,0,1) | cellphone == . - if _rc { - noi disp as err "cellphone can only take either 0 or 1 as values. Please check!" - local flagerr = 1 - } - } - } - -/* Computer */ - - if (`checkcomputer' == 1) { - cap assert missing(computer) - if _rc!=0{ - cap assert inlist(computer,0,1) | computer == . - if _rc { - noi disp as err "computer can only take either 0 or 1 as values. Please check!" - local flagerr = 1 - } - } - } - -/* Electricity */ - - if (`checkelectricity' == 1) { - cap assert missing(electricity) - if _rc!=0{ - cap assert inlist(electricity,0,1) | electricity == . - if _rc { - noi disp as err "electricity can only take either 0 or 1 as values. Please check!" - local flagerr = 1 - } - } - } - - -************************************************** - /* label variables and values for GMD database */ - ************************************************** - - cap label var countrycode "WDI three letter country codes " - cap label var year "4 digit year of the survey" - cap label var spdef "Spatial deflator (if one is used)" - cap label var weight_h "Individual weights" - cap label var weight_p "Poverty specific weights" - cap label var weighttype "Weight type (frequency, probability, analytical, importance)" - cap label var cpi "CPI ratio value of survey (rebased to `icpbase' on base 1)" - cap label var cpiperiod "Periodicity of CPI (year, year&month, year&quarter, weighted)" - cap label var ppp "PPP conversion factor. (`icpbase')" - cap label var survey "Type of survey" - cap label var vermast "Version number of master data file" - cap label var veralt "Version number of adaptation to the master data file" - cap label var harmonization "Type of harmonization" - cap label var converfactor "Conversion factor" - cap label var subnatid1 "Subnational ID - highest level" - cap label var subnatid2 "Subnational ID - second highest level" - cap label var subnatid3 "Subnational ID - third highest level" - cap label var strata "Strata" - cap label var psu "PSU" - cap label var welfare "Welfare aggregate used for estimating international poverty (provided to PovcalNet)" - cap label var welfarenom "Welfare aggregate in nominal terms" - cap label var welfaredef "Welfare aggregate spatially deflated" - cap label var welfaretype "Type of welfare measure (income, consumption or expenditure) for welfare, welfarenom, welfaredef" - cap label var welfshprosperity "Welfare aggregate for shared prosperity (if different from poverty)" - cap label var welfshprtype "Welfare type for shared prosperity indicator (income, consumption or expenditure)" - cap label var welfareother "Welfare aggregate if different welfare type is used from welfare, welfarenom, welfaredef" - cap label var welfareothertype "Type of welfare measure (income, consumption or expenditure) for welfareother" - cap label var hsize "Household size" - cap label var hhid "Household ID" - cap label var pid "Individual identifier" - cap label var urban "Urban (1) or rural (0)" - cap label var age "Age of individual (continuous)" - cap label var agecat "Age of individual (categorical)" - cap label var male "Sex of household member (male=1)" - cap label var relationharm "Relationship to head of household harmonized across all regions" - cap label var relationcs "Relationship to head of household country/region specific" - cap label var marital "Marital status" - cap label var lstatus "Labor Force Status" - cap label var minlaborage "Minimum age for employment" - cap label var empstat "Type of employment" - cap label var industrycat4 "Sector/industry of employment (4 categories)" - cap label var industrycat10 "Sector/industry of employment (10 categories)" - cap label var school "Currently in school" - cap label var literacy "Individual can read and write" - cap label var educy "Years of education" - cap label var educat4 "Level of education 4 categories" - cap label var educat5 "Level of education 5 categories" - cap label var educat7 "Level of education 7 categories" - cap label var landphone "Own Landline (fixed) phone" - cap label var cellphone "Own mobile phone (at least one)" - cap label var computer "Own Computer" - cap label var electricity "Access to electricity" - cap label var primarycomp "Primary school completion" - - - ** Keep variables - if (trim(upper("`module'"))=="ALL"){ - local gmdvars `welfare' `weight' `age' `male' `urban' `hhid' `hsize' /// - `strata' `psu' `time' `welfshprosperity' `othervariables' /// - `subnatid1' `spdef' `converfactor' `checkvars' `povweight' - - local varstodrop: list varsindata - gmdvars - if ("`varstodrop'" != "") noi disp in red _n "Caution: " in y /// - "the following variables in your dataset wont be included" /// - " in the `collection' collection:" _n _col(6) in w "`varstodrop'" - - local constantlist weighttype welfaretype welfshprtype weighttype survey vermast /// - veralt harmonization cpiperiod level ref_year - - keep `welfare' weight_h weight_p `age' `male' `urban' `hhid' `hsize' /// - `strata' `psu' `time' `welfshprosperity' `othervariables' /// - `subnatid1' `spdef' `converfactor' `checkvars' - } - -} //END OF GMD VAR CHECKS - -if (`flagerr' == 1) { - noi disp _n(2) as err "There is at least one irreconcilable error in the " /// - "dataset. Data not uploaded." - error 1 - exit -} - -*=============================================================================== -// 8) Map temporary directories and file name -*=============================================================================== -if ("`drive'" == "") local drive E -if (length("`drive'") != 1) { - disp in red "option drive should be a single letter according to the " _n /// - "availability of network locations in your computer. Default is E:\" - error -} - -local netdrive "\\wbntst01.worldbank.org\TeamDisk/`collection'" -if ("`nopovcal'"!="") mapdrive `drive', path(`netdrive') - - ************************************************** - /* path */ - ************************************************** - - if ("`savepath'" == "local") { - local path "c:\data\" - } - if ("`savepath'" != "local") & ("`savepath'" != "") { - local path "`savepath'" - } - if ("`savepath'" == "") { - if ("`nopovcal'"!="") local path "`pathmodule'" - } - - ************************************************** - /* fullname */ - ************************************************** - - if ("`fullname'" != "") { - - local fullname = trim(upper("`fullname'")) - - if !regexm(`"`fullname'"', `"^[A-Z][A-Z][A-Z]_[1-2][0-9][0-9][0-9]_[A-Z0-9\-]+_V0[1-9]_M_V0[1-9]_A_[A-Z0-9\-]+$"') { - noi disp _n in red "full name must be specified in the form " in g /// - "CCC_YYYY_SSS_VXX_M_VYY_A_HHH" in red " where," _n /// - _col(8) in g "CCC: " in w "Country code" _n /// - _col(8) in g "YYYY: " in w "Survey year" _n /// - _col(8) in g "SSS: " in w "Survey Acronym " _n /// - _col(8) in g "XX: " in w "Master two-digit version number" _n /// - _col(8) in g "YY: " in w "Alternative two-digit version number" _n /// - _col(8) in g "HHH: " in w "Harmonization name" - local flagerr = 1 - } - - lstrfun survey, regexms(`"`fullname'"', `"(^.*)_([A-Z]+[-]?[A-Z]+)_V0[1-9]_M(.*)"', 2) - lstrfun vermast, regexms(`"`fullname'"', `"(^.*)_V(0[1-9])_M(.*)"', 2) - lstrfun veralt, regexms(`"`fullname'"', `"(^.*)M_V(0[1-9])_A(.*)"', 2) - lstrfun harmonization, regexms(`"`fullname'"', `"(^.*)_([A-Z0-9\-]+)([_\-]?[0-9]?[0-9]?)$"', 2) - } - - ************************************************** - /* Default|Current directory */ - ************************************************** - - local cpath="`c(pwd)'" - if ("`nopovcal'"!="") cd "`path'" - - confirmdir `countrycode' - if ("`r(confirmdir)'" != "0") { - if ("`nopovcal'"!="") qui mkdir `countrycode' // country level - } - if ("`nopovcal'"!="") cd "`countrycode'" - - - confirmdir `countrycode'_`year'_`survey' - if ("`r(confirmdir)'" != "0") { - if ("`nopovcal'"!="") qui mkdir `countrycode'_`year'_`survey' // survey level - } - if ("`nopovcal'"!="") cd "`countrycode'_`year'_`survey'" - - confirmdir `countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection' // collection level - if ("`r(confirmdir)'" != "0") { - if ("`nopovcal'"!="") qui mkdir `countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection' // collection level - } - if ("`nopovcal'"!="") cd "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'" - - - lstrfun lastdir, regexms(`"`path'"', `"(^.*)\\([a-zA-Z_\-]+)$"', 2) - if ("`restricted'" == "") /* - */ local path "\\wbntst01.worldbank.org\TeamDisk/`collection'/datalib/all_region" // to be fixed. - - if ("`restricted'" == "restricted") /* - */ local path "\\wbntst01.worldbank.org\TeamDisk/`collection'/datalib_restricted-`reg'" // to be fixed. - - local pathcpi "\\wbntst01.worldbank.org\TeamDisk/GMD\datalib" - - cd "`cpath'" // restore original current directory - - cap mapdrive `drive', delete - - *======================================================================== - // FOLDERS FOR OTHER MODULES - *======================================================================== - - if (("`pathmodule'"!="" & "`module'"!="GPWG" & "`module'"!="ALL") | ("`pathmodule'"!="" & "`nopovcal'"!="")) { - if ("`harmonization'" == "NA"){ - local filename = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'_`module'" - local foldername = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'" - } - else { - local filename = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'_`module'" - local foldername = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'" - } - - local filepath = "`pathmodule'\\`countrycode'\\`countrycode'_`year'_`survey'\\`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'" - local filepath2 = "`filepath'" - local filename2 = "`filename'" - return local filepath = "`filepath'" - return local filename = "`filename'" - if ("`module'"!="GPWG" & "`module'"!="ALL" & "`nopovcal'"!=""){ - if ("`replace'"!="") saveold `filepath'/`filename', `replace' - else saveold `filepath'/`filename' - noi dis in green "Your file has been uploaded to:" - noi dis in white "`pathmodule'/`filename'" - exit - } - } - -*=============================================================================== -// 9) Return list and Data Signature -*=============================================================================== -************************************************** -/* Return list */ -************************************************** - -if ("`harmonization'" == "NA"){ - local filename = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'_`module'" - local foldername = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'" -} -else { - local filename = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'_`module'" - local foldername = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'" -} -local filepath = "`path'\\`countrycode'\\`countrycode'_`year'_`survey'\\`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'" - return local filepath = "`filepath'" - return local filename = "`filename'" - -************************************************** -/* Data signature */ -************************************************** -preserve - cap drop ppp - cap drop cpi - cap drop cpiperiod - datasignature - local datasig = r(datasignature) -restore -*=============================================================================== -// 10) Notes -*=============================================================================== - local date : di %tdN/D/CY date("$S_DATE", "DMY") - local username = c(username) - - if ("`harmonization'"=="NA"){ - note: `date', $S_TIME, `reg', `countrycode', `year', `survey', `harmonization', `username', `countrycode'_`year'_`survey'_V`vermast'_M_`collection', `replace', `surveylevel', `restricted', `savepath' `datasig' - } - else { - note: `date', $S_TIME, `reg', `countrycode', `year', `survey', `harmonization', `username', `countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`harmonization'_`collection', `replace', `surveylevel', `restricted', `savepath' `datasig' - } - - note `if' - note `in' - note `note' - -// extract notes as local to save in external files -local i=1 -while `i'!=. { - if `"`_dta[note`i']'"' != "" { - di `"`i'. `_dta[note`i']'"' - local i = `i' + 1 - } - else { - local i = . - } -} -cap drop __00* -*=============================================================================== -// 11) Check Vintage -*=============================================================================== -noi:dis in green "Foldername: `foldername'" -noi:dis in green "Filename: `filename'" - -*if ((`docheck'==0 | `docheck'==1) & "`collection'"=="GMD"){ -if (`docheck'==1 & "`collection'"=="GMD"){ - - noi: primus_check, country(`countrycode') verm(`vermast') vera(`veralt') year(`year') module(`module') - local replaceok = r(proceed) - - if (`replaceok'==0){ - dis as error "You requested to overwrite data, but your data is different from the one in the system" - error 378665 - exit - } - else{ - local nopovcal=1 - } -} -if ("`nopovcal'"!="") local nopovcal=1 -else local nopovcal=0 -*=============================================================================== -// 12) Send to Primus Up command -*=============================================================================== -if (("`module'"=="ALL"|"`module'"=="GPWG") & "`restricted'"==""){ - noi: primus_up, nopovcal(`nopovcal') output(`output') natcode(`countrycode') year(`year') /// - weflist(`welfare_primus') vermast_p(`vermast') veralt_p(`veralt') surveys(`foldername') /// - ctryname(`primus_cname') filename(`filename') reg(`reg') refyear(`refyear') /// - no_pweight(`no_pweight') povweight(weight_p) filepath(`filepath2') filename(`filename') hhlev(`hhlev') byvar(`byvar') collection(`collection') - - return local primusid = "`e(transid)'" -} -*=============================================================================== -// 13) Log file -*=============================================================================== - - if ("`restricted'" == "") { - local restricted unrestricted - } - - cap file open `hh' using "\\wbntst01.worldbank.org\TeamDisk/`collection'/datalib\_log\log_upload2.csv", write text append - - if ("`harmonization'"=="NA"){ - cap file write `hh' "`date', $S_TIME, `countrycode', `year', `survey', master , `username', V`vermast', V`veralt', NA , `countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection', `replace', `surveylevel', `reg', `restricted', `savepath', `path'" _n - } - else { - cap file write `hh' "`date', $S_TIME, `countrycode', `year', `survey', `harmonization', `username', V`vermast', V`veralt', `countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`harmonization'_`collection', `replace', `surveylevel', `reg', `restricted', `savepath', `path'" _n - } - - cap file close `hh' - - - cd "`cpath'" // restore original current directory - -} // end of Quietly - -if ("`keepdata'" != "") { - use `_tmp', clear -} - -end //END OF PRIMUS UPLOAD!! -************************************************** -/* Program to map temporally drives*/ -************************************************** - -cap program drop mapdrive -program define mapdrive - syntax anything(name=drive), [path(string) delete] - local drive = upper("`drive'") - shell net use /del `drive': /Y - if ("`delete'" == "") shell net use `drive': `path' /PERSISTENT:no -end - - -*=============================================================================== -//Program for countrynames -*=============================================================================== - - -cap program drop _countryname -program define _countryname - -qui { - tempname n - tempfile names - - postfile `n' str3(region countrycode) str30 countryname using `names' , replace - - * postfile `n' str3(region countrycode) str30 countryname using countrynames , replace - - post `n' ("EAP") ("ASM") ("American Samoa") - post `n' ("EAP") ("AUS") ("Australia") - post `n' ("EAP") ("BRN") ("Brunei Darussalam") - post `n' ("EAP") ("CHN") ("China") - post `n' ("EAP") ("FJI") ("Fiji") - post `n' ("EAP") ("FSM") ("Micronesia, Fed. Sts.") - post `n' ("EAP") ("GUM") ("Guam") -* post `n' ("EAP") ("HKG") ("Hong Kong SAR, China") - post `n' ("EAP") ("IDN") ("Indonesia") - post `n' ("EAP") ("JPN") ("Japan") - post `n' ("EAP") ("KHM") ("Cambodia") - post `n' ("EAP") ("KIR") ("Kiribati") - post `n' ("EAP") ("KOR") ("Korea, Rep.") - post `n' ("EAP") ("LAO") ("Lao PDR") -* post `n' ("EAP") ("MAC") ("Macao SAR, China") - post `n' ("EAP") ("MHL") ("Marshall Islands") - post `n' ("EAP") ("MMR") ("Myanmar") - post `n' ("EAP") ("MNG") ("Mongolia") - post `n' ("EAP") ("MNP") ("Northern Mariana Islands") - post `n' ("EAP") ("MYS") ("Malaysia") - post `n' ("EAP") ("NCL") ("New Caledonia") - post `n' ("EAP") ("NRU") ("Nauru") - post `n' ("EAP") ("NZL") ("New Zealand") - post `n' ("EAP") ("PHL") ("Philippines") - post `n' ("EAP") ("PLW") ("Palau") - post `n' ("EAP") ("PNG") ("Papua New Guinea") -* post `n' ("EAP") ("PRK") ("Korea, Dem. People's Rep.") - post `n' ("EAP") ("PYF") ("French Polynesia") - post `n' ("EAP") ("SGP") ("Singapore") - post `n' ("EAP") ("SLB") ("Solomon Islands") - post `n' ("EAP") ("THA") ("Thailand") - post `n' ("EAP") ("TLS") ("Timor-Leste") - post `n' ("EAP") ("TON") ("Tonga") - post `n' ("EAP") ("TUV") ("Tuvalu") -* post `n' ("EAP") ("TWN") ("Taiwan, China") - post `n' ("EAP") ("VNM") ("Vietnam") - post `n' ("EAP") ("VUT") ("Vanuatu") - post `n' ("EAP") ("WSM") ("Samoa") - post `n' ("ECA") ("ALB") ("Albania") - post `n' ("ECA") ("AND") ("Andorra") - post `n' ("ECA") ("ARM") ("Armenia") - post `n' ("ECA") ("AUT") ("Austria") - post `n' ("ECA") ("AZE") ("Azerbaijan") - post `n' ("ECA") ("BEL") ("Belgium") - post `n' ("ECA") ("BGR") ("Bulgaria") - post `n' ("ECA") ("BIH") ("Bosnia and Herzegovina") - post `n' ("ECA") ("BLR") ("Belarus") - post `n' ("ECA") ("CHE") ("Switzerland") - post `n' ("ECA") ("CHI") ("Channel Islands") - post `n' ("ECA") ("CYP") ("Cyprus") - post `n' ("ECA") ("CZE") ("Czech Republic") - post `n' ("ECA") ("DEU") ("Germany") - post `n' ("ECA") ("DNK") ("Denmark") - post `n' ("ECA") ("ESP") ("Spain") - post `n' ("ECA") ("EST") ("Estonia") - post `n' ("ECA") ("FIN") ("Finland") - post `n' ("ECA") ("FRA") ("France") - post `n' ("ECA") ("FRO") ("Faroe Islands") - post `n' ("ECA") ("GBR") ("United Kingdom") - post `n' ("ECA") ("GEO") ("Georgia") - post `n' ("ECA") ("GIB") ("Gibraltar") - post `n' ("ECA") ("GRC") ("Greece") - post `n' ("ECA") ("GRL") ("Greenland") - post `n' ("ECA") ("HRV") ("Croatia") - post `n' ("ECA") ("HUN") ("Hungary") - post `n' ("ECA") ("IMN") ("Isle of Man") - post `n' ("ECA") ("IRL") ("Ireland") - post `n' ("ECA") ("ISL") ("Iceland") - post `n' ("ECA") ("ITA") ("Italy") - post `n' ("ECA") ("KAZ") ("Kazakhstan") - post `n' ("ECA") ("KGZ") ("Kyrgyz Republic") - post `n' ("ECA") ("KSV") ("Kosovo") - post `n' ("ECA") ("LIE") ("Liechtenstein") - post `n' ("ECA") ("LTU") ("Lithuania") - post `n' ("ECA") ("LUX") ("Luxembourg") - post `n' ("ECA") ("LVA") ("Latvia") - post `n' ("ECA") ("MCO") ("Monaco") - post `n' ("ECA") ("MDA") ("Moldova") - post `n' ("ECA") ("MKD") ("Macedonia, FYR") - post `n' ("ECA") ("MNE") ("Montenegro") - post `n' ("ECA") ("NLD") ("Netherlands") - post `n' ("ECA") ("NOR") ("Norway") - post `n' ("ECA") ("POL") ("Poland") - post `n' ("ECA") ("PRT") ("Portugal") - post `n' ("ECA") ("ROU") ("Romania") - post `n' ("ECA") ("RUS") ("Russian Federation") - post `n' ("ECA") ("SMR") ("San Marino") - post `n' ("ECA") ("SRB") ("Serbia") - post `n' ("ECA") ("SVK") ("Slovak Republic") - post `n' ("ECA") ("SVN") ("Slovenia") - post `n' ("ECA") ("SWE") ("Sweden") - post `n' ("ECA") ("TJK") ("Tajikistan") - post `n' ("ECA") ("TKM") ("Turkmenistan") - post `n' ("ECA") ("TUR") ("Turkey") - post `n' ("ECA") ("UKR") ("Ukraine") - post `n' ("ECA") ("UZB") ("Uzbekistan") - post `n' ("LAC") ("ABW") ("Aruba") - post `n' ("LAC") ("ARG") ("Argentina") - post `n' ("LAC") ("ATG") ("Antigua and Barbuda") - post `n' ("LAC") ("BHS") ("Bahamas, The") - post `n' ("LAC") ("BLZ") ("Belize") - post `n' ("LAC") ("BOL") ("Bolivia") - post `n' ("LAC") ("BRA") ("Brazil") - post `n' ("LAC") ("BRB") ("Barbados") - post `n' ("LAC") ("CHL") ("Chile") - post `n' ("LAC") ("COL") ("Colombia") - post `n' ("LAC") ("CRI") ("Costa Rica") - post `n' ("LAC") ("CUB") ("Cuba") - post `n' ("LAC") ("CUW") ("Curaçao") - post `n' ("LAC") ("CYM") ("Cayman Islands") - post `n' ("LAC") ("DMA") ("Dominica") - post `n' ("LAC") ("DOM") ("Dominican Republic") - post `n' ("LAC") ("ECU") ("Ecuador") - post `n' ("LAC") ("GRD") ("Grenada") - post `n' ("LAC") ("GTM") ("Guatemala") - post `n' ("LAC") ("GUY") ("Guyana") - post `n' ("LAC") ("HND") ("Honduras") - post `n' ("LAC") ("HTI") ("Haiti") - post `n' ("LAC") ("JAM") ("Jamaica") - post `n' ("LAC") ("KNA") ("St. Kitts and Nevis") - post `n' ("LAC") ("LCA") ("St. Lucia") - post `n' ("LAC") ("MAF") ("St. Martin (French part)") - post `n' ("LAC") ("MEX") ("Mexico") - post `n' ("LAC") ("NIC") ("Nicaragua") - post `n' ("LAC") ("PAN") ("Panama") - post `n' ("LAC") ("PER") ("Peru") - post `n' ("LAC") ("PRI") ("Puerto Rico") - post `n' ("LAC") ("PRY") ("Paraguay") - post `n' ("LAC") ("SLV") ("El Salvador") - post `n' ("LAC") ("SUR") ("Suriname") - post `n' ("LAC") ("SXM") ("Sint Maarten (Dutch part)") - post `n' ("LAC") ("TCA") ("Turks and Caicos Islands") - post `n' ("LAC") ("TTO") ("Trinidad and Tobago") - post `n' ("LAC") ("URY") ("Uruguay") - post `n' ("LAC") ("VCT") ("St. Vincent and the Grenadines") - post `n' ("LAC") ("VEN") ("Venezuela, RB") - post `n' ("LAC") ("VGB") ("British Virgin Islands") - post `n' ("LAC") ("VIR") ("Virgin Islands (U.S.)") - post `n' ("MNA") ("ARE") ("United Arab Emirates") - post `n' ("MNA") ("BHR") ("Bahrain") - post `n' ("MNA") ("DJI") ("Djibouti") - post `n' ("MNA") ("DZA") ("Algeria") - post `n' ("MNA") ("EGY") ("Egypt, Arab Rep.") - post `n' ("MNA") ("IRN") ("Iran, Islamic Rep.") - post `n' ("MNA") ("IRQ") ("Iraq") - post `n' ("MNA") ("ISR") ("Israel") - post `n' ("MNA") ("JOR") ("Jordan") - post `n' ("MNA") ("KWT") ("Kuwait") - post `n' ("MNA") ("LBN") ("Lebanon") - post `n' ("MNA") ("LBY") ("Libya") - post `n' ("MNA") ("MAR") ("Morocco") - post `n' ("MNA") ("MLT") ("Malta") - post `n' ("MNA") ("OMN") ("Oman") - post `n' ("MNA") ("PSE") ("West Bank and Gaza") - post `n' ("MNA") ("QAT") ("Qatar") - post `n' ("MNA") ("SAU") ("Saudi Arabia") - post `n' ("MNA") ("SYR") ("Syrian Arab Republic") - post `n' ("MNA") ("TUN") ("Tunisia") - post `n' ("MNA") ("YEM") ("Yemen, Rep.") - post `n' ("NAC") ("BMU") ("Bermuda") - post `n' ("NAC") ("CAN") ("Canada") - post `n' ("NAC") ("USA") ("United States") - post `n' ("SAR") ("AFG") ("Afghanistan") - post `n' ("SAR") ("BGD") ("Bangladesh") - post `n' ("SAR") ("BTN") ("Bhutan") - post `n' ("SAR") ("IND") ("India") - post `n' ("SAR") ("LKA") ("Sri Lanka") - post `n' ("SAR") ("MDV") ("Maldives") - post `n' ("SAR") ("NPL") ("Nepal") - post `n' ("SAR") ("PAK") ("Pakistan") - post `n' ("SSA") ("AGO") ("Angola") - post `n' ("SSA") ("BDI") ("Burundi") - post `n' ("SSA") ("BEN") ("Benin") - post `n' ("SSA") ("BFA") ("Burkina Faso") - post `n' ("SSA") ("BWA") ("Botswana") - post `n' ("SSA") ("CAF") ("Central African Republic") - post `n' ("SSA") ("CIV") ("Côte dIvoire") - post `n' ("SSA") ("CMR") ("Cameroon") - post `n' ("SSA") ("COD") ("Congo, Dem. Rep.") - post `n' ("SSA") ("COG") ("Congo, Rep.") - post `n' ("SSA") ("COM") ("Comoros") - post `n' ("SSA") ("CPV") ("Cabo Verde") - post `n' ("SSA") ("ERI") ("Eritrea") - post `n' ("SSA") ("ETH") ("Ethiopia") - post `n' ("SSA") ("GAB") ("Gabon") - post `n' ("SSA") ("GHA") ("Ghana") - post `n' ("SSA") ("GIN") ("Guinea") - post `n' ("SSA") ("GMB") ("Gambia, The") - post `n' ("SSA") ("GNB") ("Guinea-Bissau") - post `n' ("SSA") ("GNQ") ("Equatorial Guinea") - post `n' ("SSA") ("KEN") ("Kenya") - post `n' ("SSA") ("LBR") ("Liberia") - post `n' ("SSA") ("LSO") ("Lesotho") - post `n' ("SSA") ("MDG") ("Madagascar") - post `n' ("SSA") ("MLI") ("Mali") - post `n' ("SSA") ("MOZ") ("Mozambique") - post `n' ("SSA") ("MRT") ("Mauritania") - post `n' ("SSA") ("MUS") ("Mauritius") - post `n' ("SSA") ("MWI") ("Malawi") - post `n' ("SSA") ("NAM") ("Namibia") - post `n' ("SSA") ("NER") ("Niger") - post `n' ("SSA") ("NGA") ("Nigeria") - post `n' ("SSA") ("RWA") ("Rwanda") - post `n' ("SSA") ("SDN") ("Sudan") - post `n' ("SSA") ("SEN") ("Senegal") - post `n' ("SSA") ("SLE") ("Sierra Leone") - post `n' ("SSA") ("SOM") ("Somalia") - post `n' ("SSA") ("SSD") ("South Sudan") - post `n' ("SSA") ("STP") ("São Tomé and Principe") - post `n' ("SSA") ("SWZ") ("Swaziland") - post `n' ("SSA") ("SYC") ("Seychelles") - post `n' ("SSA") ("TCD") ("Chad") - post `n' ("SSA") ("TGO") ("Togo") - post `n' ("SSA") ("TZA") ("Tanzania") - post `n' ("SSA") ("UGA") ("Uganda") - post `n' ("SSA") ("ZAF") ("South Africa") - post `n' ("SSA") ("ZMB") ("Zambia") - post `n' ("SSA") ("ZWE") ("Zimbabwe") - - postclose `n' - - use `names', clear - label var region "Region" - label var countrycode "Country Code" - label var countryname "Country Name" - - compress -} - -end +*! primus_upload.ado +*! Joao Pedro Azevedo, Raul Andres Castaneda, Paul Corral, Minh Cong Nguyen +*! December 2019 + +cap program drop primus_upload +program define primus_upload, rclass + + version 11.0 + + syntax [if] [in] , /// + Countrycode(string) /// + Year(numlist >1900 int max=1) /// + WELFare(varname) /// + welfaretype(string) /// + WELFSHprosperity(varname) /// + welfshprtype(string) /// + weight(varname) /// + weighttype(string) /// + HSize(varname) /// + hhid(varname) /// + MODule(string) /// + SURvey(string) /// + [ /// + cpi(varname) /// + CPIPERiod(string) /// + ppp(varname) /// + pid(varname) /// + collection(string) /// + POVWeight(varname) /// + drive(string) /// + SUBnatid1(varname) /// + spdef(varname) /// + Time(string) /// + welfarenom(varname) /// + welfaredef(varname) /// + welfareother(varname) /// + welfareothertype(string) /// + age(varname) /// + male(varname) /// + URBan(varname) /// + tfood(varname) /// + tnfood(varname) /// + rent(varname) /// + durgood(varname) /// + health(varname) /// + VERMast(string) /// + HARmonization(string) /// + VERAlt(string) /// + FULLname(string) /// + CONVERfactor(varname) /// + OTHERVARiables(varlist) /// + STRATa(varname) /// + psu(varname) /// + note(string) /// + SAVEPath(string) /// + ICPbase(integer 2011) /// + save13 /// + restricted /// + replace /// + NOPOVcal /// + level(varname) /// + output(string) /// + welfare_primus(string) /// + REFYear(string) /// + AUTOversion /// + OVERwrite /// + hhlev(integer 0) /// + ] +*=============================================================================== +//00:Keep Data; and necessary programs +*=============================================================================== +qui{ +if ("`keepdata'" != "") { + tempfile _tmp + save `_tmp', replace +} + +//Necessary ados +cap which lstrfun +if _rc ssc install lstrfun + +cap which mdesc +if _rc ssc install mdesc + +cap which confirmdir +if _rc ssc install confirmdir + + +*=============================================================================== +// 01:Error checks +*=============================================================================== +//Split fullname +if ("`fullname'"!=""){ + local fullname = trim(upper("`fullname'")) + + tokenize `fullname', parse("_") + local countrycode = "`1'" + local year = "`3'" + local survey = "`5" + local verm = subinstr("`7'","V","",.) + local vera = subinstr("`11'","V","",.) + local collection = "`15'" + if ("`17'"!="") local module = "`17'" + + local fullname +} +//Upper case all necessary inputs +local uppercase countrycode module survey harmonization collection vermast veralt /// +fullname welfaretype welfshprtype welfareothertype weighttype + + foreach x of local uppercase{ + if ("``x''"!="") local `x' = upper(trim("``x''")) + local remove1 `remove1' `x' + } + +//...Check for uniqueness, before anything! +if ("`pid'"==""){ +cap isid `hhid' + if (_rc!=0){ + dis as error "Data is not unique at `hhid' level, please revise" + error 459 + exit + } +} +else{ +cap isid `hhid' `pid' + if (_rc!=0){ + dis as error "Data is not unique at `hhid' and `pid' level, please revise" + error 459 + exit + } +} + +// Check if welfare and weights are double +foreach x of varlist `welfare' `weight' `povweight'{ + cap confirm existence `x' + if (_rc==0){ + * Examine precision of variables being uploaded + local thetype: type `x' + if ("`thetype'"!="double") & ("`nopovcal'"!=""){ //display error for nopovcal uploads, not dialog box + display as error "It is preferable that you upload variable `x' with double precision." + } + else { + capture window stopbox rusure "It is preferable that you upload variable `x' with double precision." /// + "Would you like to continue as is?" + local stwrk = _rc==0 + if (`stwrk'==0){ //If user selects "No" to the previous dialog box + dis as error "Variable `x' must be stored with double precision." + error 34567 + exit + } + } + + qui: sum `x' + if (r(mean) ==0){ + dis as error "Variable `x' has mean 0, this should not be the case" + error 198 + exit + } + } + else{ + dis as error "Variable `x' not found" + error 198 + exit + } +} + + + +//Remove vars from othervars +local othervariables : list othervariables - remove1 +local othervariables : list othervariables - welfare +local othervariables : list othervariables - weight +local othervariables : list othervariables - povweight + + + +//Collection +if ("`collection'"=="") local collection GMD +local collection =trim(upper("`collection'")) +if (inlist("`collection'", "GMD", "PCN")==0){ + dis as error "`collection' is not a valid collection, only GMD or PCN are accepted" + error 1203934 + exit +} + +//Specify module and ensure path is there +if ("`module'"==""){ + dis as error "You must specify a module, such as _ALL" + error 12734764 + exit +} +local modulelist ALL I2D2 GPWG +local _modch: list modulelist & module +if ("`_modch'"==""){ + dis as error "You have specified an unrecognized module" + error 1637344 + exit +} + +//Ensure excel file for file uploads is specified +if (trim(upper("`module'"))=="ALL"|trim(upper("`module'"))=="GPWG"){ + if ("`output'"==""){ + display as error "You must specify an excel file for storing upload details" + error 102939 + exit + } + else{ + local _dd=c(current_date) + putexcel set "`output'", sh("`_dd'", replace) modify + putexcel A1=("Unique_ID") B1=("Category") C1=("`_dd'") + } +} + +*=============================================================================== +// 02:Check for valid inputs +*=============================================================================== +local flagerr = 0 +//Country code checks +local countrycode = trim(upper("`countrycode'")) + if (length("`countrycode'")!=3){ + display as error "country code must be 3 digit iso country code" + local flagerr=1 + } + +local _thenats AFG ALB DZA ASM AND AGO ATG ARB ARG ARM ABW AUS AUT AZE BHS BHR /// +BGD BRB BLR BEL BLZ BEN BMU BTN BOL BIH BWA BRA BRN BGR BFA BDI KHM CMR CAN CPV /// +CSS CYM CAF CUW TCD CHI CHL CHN COL COM COD COG CRI CIV HRV CUB CUW CYP CZE DNK /// +DJI DMA DOM ECU EGY SLV GNQ ERI EST ETH EUU FRO FJI FIN FRA PYF GAB GMB GEO DEU /// +GHA GRC GRL GRD GUM GTM GIN GNB GUY HTI HND HKG HUN ISL IND IDN IRN IRQ IRL IMN /// +ISR ITA JAM JPN JOR KAZ KEN KIR PRK KOR KSV KWT KGZ LAO LVA LBN LSO LBR LBY LIE /// +LTU LUX MAC MKD MDG MWI MYS MDV MLI MLT MHL MRT MUS MEX FSM MDA MCO MNG MNE MAR /// +MOZ MMR NAM NPL NLD NCL NZL NIC NER NGA MNP NOR INX OED OMN OSS PSS PAK PLW PAN /// +PNG PRY PER PHL POL PRT PRI QAT ROU RUS RWA WSM SMR STP SAU SEN SRB SYC SLE SGP /// +SXM SVK SVN SST SLB SOM ZAF SSD ESP LKA KNA LCA MAF VCT SDN SUR SWZ SWE CHE SYR /// +TJK TZA THA TLS TGO TON TTO TUN TUR TKM TCA TUV UGA UKR ARE GBR USA URY UZB VUT /// +VEN VNM VIR PSE YEM ZMB ZWE SXM MAF + +local _natcheck: list _thenats & countrycode + +if ("`_natcheck'"==""){ + display as error "Country code not recognized, please provide a valid country code" + local flagerr=1 +} + +// Year +if length("`year'")!=4 { + noi di as err "year variable needs to be specified with four digits" + local flagerr = 1 +} + +//Check provided survey name is valid! +preserve +primus_vintage, country(`countrycode') svyname +local svnamestocheck = r(thesurveys) +local _aok: list survey & svnamestocheck +local _aok = "`_aok'"!="" +restore + + if (`_aok'==0){ + dis as error "The survey name provided does not exist, talk to central team" + error 3699 + exit + } + +//Welfare type +local flag2 = inlist("`welfaretype'", "INC", "CONS", "EXP") +if (`flag2' != 1) { + noi di as err "eligible welfare types: INC=INCOME; CONS=CONSUMPTION; EXP=EXPENDITURE" + local flagerr = 1 +} +//Welfare shared prosperity type +local flag2 = inlist("`welfshprtype'", "INC", "CONS", "EXP") +if (`flag2' != 1) { + noi di as err "eligible shared prosperity welfare types: INC=INCOME; CONS=CONSUMPTION; EXP=EXPENDITURE" + local flagerr = 1 +} +//Welfare other type! +if ("`welfareother'" != "") { + local flag2 = inlist("`welfareothertype'", "INC", "CONS", "EXP") + if (`flag2' != 1) { + noi di as err "eligible other welfare types: INC=INCOME; CONS=CONSUMPTION; EXP=EXPENDITURE" + local flagerr = 1 + } +} +//Weight type +local flag2 = inlist("`weighttype'", "FW", "PW", "AW", "IW") +if (`flag2' != 1) { + noi di as err "eligible weight types: FW=Frequency weights; PW=Probability weights; AW=Analytical weights; IW=Importance weights" + local flagerr = 1 +} +//Spatial Deflation +if ("`spdef'" != "" & "`subnatid1'" == ""){ + noi di as err "Spatial deflator can only be entered if data contain subnational ID. Please check." + local flagerr = 1 +} +*=============================================================================== +// 03:Program assigned inputs +*=============================================================================== +//Region codes +preserve + _countryname + levelsof region if countrycode=="`countrycode'", local(reg) clean + local good1: list sizeof reg + if (`good1'!=1){ + dis as error "Country code not assigned to a region" + local flagerr = 1 + } +restore +//Path Module +local pathmodule = "\\wbntst01.worldbank.org\TeamDisk\GPWG\datalib\all_region_primus\" + +//By var +local byvar `level' + +//Pov weight --> If missing -> Weight +if ("`povweight'"==""){ + local povweight `weight' + local no_pweight = 1 +} +else local no_pweight = 0 + +//Country name +preserve + _countryname + levelsof countryname if countrycode=="`countrycode'", local(primus_cname) +restore + +//Local with all variables in data +local varsindata +foreach x of varlist *{ + local varsindata `varsindata' `x' +} + +// If level is not specified +if "`level'"=="" { + cap drop _all_ + gen _all_ = 1 + local level2 _all_ +} +else { + gen temp = `level' + local level2 temp +} + +//Output +if ("`output'"==""){ + local output "c:\Users\\`c(username)'\Downloads\" +} + +//Weflare primus, if missing +if ("`welfare_primus'"=="") local welfare_primus welfare + +//Ref Year, if missing +if ("`refyear'"=="") local refyear = `year' + +*=============================================================================== +// 04:Version control +*=============================================================================== +//Autoversion + +if ("`autoversion'"!="" & "`collection'"=="GMD"){ +preserve + if (upper("`module'")=="GPWG" | upper("`module'")=="ALL") { + local nm = lower("`module'") + primus_vintage, country(`countrycode') year(`year') max svy(`survey') + + if ("`vermast'"=="") local vermast = "`r(maxm)'" + local veralt = "`r(maxa)'" + } + else{ + primus_vintage, country(`countrycode') year(`year') module(`module') + if ("`vermast'"=="") local vermast = "`r(newm)'" + local veralt = "`r(newa)'" + } +restore +} + + +//Version requirements once we have assigned these +if length("`vermast'")!=2 & "`fullname'" == ""{ + noi di as err "master version needs to have two digits" + local flagerr = 1 + local _vm=0 +} +else local _vm=1 + +if length("`veralt'")!=2 & "`fullname'" == ""{ + noi di as err "harmonization version needs to have two digits" + local flagerr = 1 + local _va=0 +} +else local _va = 1 + +//Check if vintages exists +if (`_vm'==1 & `_va'==1){ +preserve + primus_vintage, country(`countrycode') year(`year') svy(`survey') + local nm = lower(trim("`module'")) + local newyear=r(newy) + local _v_a = r(`nm'_a) + local _v_m = r(`nm'_m) + local _v_a = subinstr("`_v_a'", "V","",.) + local _v_a = subinstr("`_v_a'", ".","",.) + local _v_m = subinstr("`_v_m'", "V","",.) + local _v_m = subinstr("`_v_m'", ".","",.) +restore + if ("`_v_a'"=="`veralt'" & "`_v_m'"=="`vermast'" & "`newyear'"!="1"){ + if ("`overwrite'"==""){ + noi dis as error "You may not overwrite an existing vintage" + local docheck=0 + local flagerr = 1 + error 100000 + } + else local docheck=1 + } + else{ + local docheck = 0 + } +} + +//Full name and components +if ("`fullname'" == "") & (("`survey'" == "") | ("`vermast'" == "")) & (("`harmonization'" == "") | ("`veralt'" == "")){ + noi di as err "Either full name or name components have to be specified. Please check." + local flagerr = 1 +} + + +*=============================================================================== +// 6) Variables to be kept for collections, Select, rename, label Variables +// and value labels +*=============================================================================== + +if ("`collection'" == "GMD" & "`module'"=="GPWG") { + + local gpwgvars `welfare' `weight' `age' `male' `urban' `hhid' `hsize' `cpi' /// + `ppp' `strata' `psu' `time' `welfshprosperity' `othervariables' /// + `subnatid1' `spdef' `converfactor' `povweight' + local varstodrop: list varsindata - gpwgvars + if ("`varstodrop'" != "") noi disp in red _n "Caution: " in y /// + "the following variables in your dataset wont be included" /// + " in the `collection' collection:" _n _col(6) in w "`varstodrop'" + + keep `welfare' `weight' `age' `male' `urban' `hhid' `hsize' `cpi' /// + `ppp' `strata' `psu' `time' `welfshprosperity' `othervariables' /// + `subnatid1' `spdef' `converfactor' `povweight' `pid' +} + +if ("`collection'"=="PCN"){ + keep `hsize' `urban' `weight' `povweight' `hhid' `welfare' `cpi' `ppp' +} + + ************************************************** + /* select and rename variables */ + ************************************************** + + + cap clonevar pp_welfare =`welfare' + cap clonevar pp_welfarenom =`welfarenom' + cap clonevar pp_welfaredef =`welfaredef' + cap clonevar pp_welfareother =`welfareother' + cap clonevar pp_weight_h =`weight' + cap clonevar pp_weight_p =`povweight' + cap clonevar pp_age =`age' + cap clonevar pp_male =`male' + cap clonevar pp_urban =`urban' + cap clonevar pp_hsize =`hsize' + cap clonevar pp_hhid =`hhid' + cap clonevar pp_cpi =`cpi' + cap clonevar pp_ppp =`ppp' + cap clonevar pp_strata =`strata' + cap clonevar pp_psu =`psu' + cap clonevar pp_welfshprosperity =`welfshprosperity' + cap clonevar pp_subnatid1 =`subnatid1' + cap clonevar pp_spdef =`spdef' + cap clonevar pp_converfactor =`converfactor' + local myvardrop `welfare' `welfarenom' `welfaredef' `welfareother' /// + `weight' `age' `male' `urban' `hsize' `hhid' `cpi' /// + `ppp' `strata' `psu' `welfshprosperity' `subnatid1' /// + `spdef' `converfactor' + + foreach V of local myvardrop{ + cap drop `V' + } + cap drop `povweight' + renpfix pp_ + + cap drop countrycode + cap drop year + + cap gen countrycode = upper("`countrycode'") + cap gen year = `year' + cap gen welfaretype = upper("`welfaretype'") + cap gen welfshprtype = upper("`welfshprtype'") + + if ("`welfareothertype'" != "") { + cap gen welfareothertype = upper("`welfareothertype'") + } + + cap gen weighttype = upper("`weighttype'") + cap gen cpiperiod = "`cpiperiod'" + + + cap gen survey = "`survey'" + cap gen vermast = "`vermast'" + cap gen veralt = "`veralt'" + cap gen harmonization = "`harmonization'" + + * ICPbase + + if !inlist(`icpbase', 2005, 2011) { + noi disp in red "ICPbase variable must be either 2005 or 2011. Default 2011." + local flagerr = 1 + } + else { + cap gen icpbase = `icpbase' + label var icpbase "ICP reference year `icpbase'" + } + + ** other variables + if ("`age'" != "") | ("`male'" != "") { + local surveylevel "individual" + order countrycode year hhid welfaretype welfare //age male urban cpi* ppp weight + } + else { + local surveylevel "household" + order countrycode year hhid welfaretype welfare //urban cpi* ppp weight + } + + ************************************************** + /* label variables and values for GPWG databse */ + ************************************************** + + cap label var countrycode "WDI three letter country codes " + cap label var year "4 digit year of the survey" + cap label var spdef "Spatial deflator (if one is used)" + cap label var weight_h "Weight" + cap label var weight_p "Weight for poverty calculation" + cap label var weighttype "Weight type (frequency, probability, analytical, importance)" + cap label var cpi "CPI ratio value of survey (rebased to `icpbase' on base 1)" + cap label var cpiperiod "Periodicity of CPI (year, year&month, year&quarter, weighted)" + cap label var ppp "PPP conversion factor. (`icpbase')" + cap label var survey "Type of survey" + cap label var vermast "Version number of master data file" + cap label var veralt "Version number of adaptation to the master data file" + cap label var harmonization "Type of harmonization" + cap label var converfactor "Conversion factor" + cap label var subnatid1 "Subnational ID - highest level" + cap label var subnatid2 "Subnational ID - second highest level" + cap label var subnatid3 "Subnational ID - third highest level" + cap label var strata "Strata" + cap label var psu "PSU" + cap label var welfare "Welfare aggregate used for estimating international poverty (provided to PovcalNet)" + cap label var welfarenom "Welfare aggregate in nominal terms" + cap label var welfaredef "Welfare aggregate spatially deflated" + cap label var welfaretype "Type of welfare measure (income, consumption or expenditure) for welfare, welfarenom, welfaredef" + cap label var welfshprosperity "Welfare aggregate for shared prosperity (if different from poverty)" + cap label var welfshprtype "Welfare type for shared prosperity indicator (income, consumption or expenditure)" + cap label var welfareother "Welfare aggregate if different welfare type is used from welfare, welfarenom, welfaredef" + cap label var welfareothertype "Type of welfare measure (income, consumption or expenditure) for welfareother" + cap label var hsize "Household size" + cap label var hhid "Household ID" + + ************************************************** + /* Value labels values */ + ************************************************** + cap levelsof male, local(ckmale) + if regexm("0 1","`ckmale'") { + cap lab define male 1 Male 0 Female, modify + cap lab values male male + } + else { + if "`male'"!="" { + noi di as err "male variable [`male'] has values other than 0 and 1 (i.e. male=1, female=0), please check." + local flagerr = 1 + } + } + + cap levelsof urban, local(ckurban) + if regexm("0 1","`ckurban'") { + cap lab define urban 1 Urban 0 Rural, modify + cap lab values urban urban + } + else { + if "`urban'"!="" { + noi di as err "urban variable [`urban'] has values other than 0 and 1 (i.e. urban=1, rural=0), please check." + local flagerr = 1 + } + } + +*============================================================================== + //7: Variables Checks +*=============================================================================== +//GPWG Variable CHECKS +if (("`collection'" == "GMD"|"`collection'" == "PCN") & "`module'"=="GPWG"){ + local nums welfare weight age hsize + + foreach x of local nums{ + cap confirm var ``x'' + local is = _rc==0 + if (`is'==1){ + cap confirm numeric variable ``x'', exact + local is1 = _rc==0 + if (`is1'==0) local notnum `notnum' ``x'' + } + } + + if ("`notnum'"!="") { + dis as err "The following variables should be numeric:" /// + _n _col(6) in w "`notnum'" + local flagerr=1 + } + + if "`ppp'"!="" & "`countrycode'"!="IND" & "`countrycode'"!="IDN" & "`countrycode'"!="CHN"{ + qui sum ppp + + if (r(Var)>1e-6) { + noi di as err "PPP conversion factor is not constant within survey, please check." + local flagerr = 1 + } + } + + if ("`cpi'" != "" & "`countrycode'"!="IND" & "`countrycode'"!="IDN" & "`countrycode'"!="CHN") { + qui sum cpi + if (r(Var)>1e-6) { + noi di as err "CPI is not constant within survey, please specify period of reference variable." + local flagerr = 1 + } + } + + if ("`subnatid1'" != "") { + capture confirm string var subnatid1 + if (_rc) { + noi di as err "Subnatid1 was not correctly specified. Please, make sure that the following naming convention (string) is used: # – String" + local flagerr =1 + } + cap levelsof subnatid1, local(mysub) + local mysub: list sizeof mysub + if (`mysub'==1){ + noi dis as err "Subnatid1 is constant for all entries, please revise" + local flagerr =1 + } + + } + + + if ("`spdef'" != "") { + qui sum spdef + local var2spdef = r(Var) + if (`var2spdef' == 0) /*& (("`bypass'" != ""))*/ { + noi di as err "Spatial deflator is constant for all entries. Please check." + local flagerr = 1 + } + } + + /*household weights */ + if ("`weight'"!="" & "`countrycode'"!="PSE" & "`countrycode'"!="MAR") { + sort hhid + qui by hhid: egen double min=min(weight_h) + qui by hhid: egen double max=max(weight_h) + gen weightcheck2= min==max + qui: sum weightcheck2 + local wvalid = r(mean) + if `wvalid'!=0 { + noi di in red "Caution: "in y "Household weights are not unique within households. Please check." + } + drop min max weightcheck2 + } + + if ("`povweight'"!="" & "`countrycode'"!="PSE" & "`countrycode'"!="MAR") { + sort hhid + qui by hhid: egen double min=min(weight_p) + qui by hhid: egen double max=max(weight_p) + gen weightcheck2= min==max + qui: sum weightcheck2 + local wvalid = r(mean) + if `wvalid'!=0 { + noi di in red "Caution: "in y "Household weights for poverty are not unique within households. Please check." + } + drop min max weightcheck2 + } + +} + +//GMD Checks +if (trim(upper("`module'"))=="ALL" & "`collection'"=="GMD"){ + local checkvars spdef converfactor subnatid1 subnatid2 subnatid3 /// + strata psu welfarenom welfaredef welfshprosperity welfshprtype /// + welfareother welfareothertype pid agecat relationharm relationcs /// + marital lstatus minlaborage empstat industrycat10 industrycat4 school /// + literacy educy educat4 educat5 educat7 landphone cellphone computer /// + electricity primarycomp countrycode year welfaretype weighttype age /// + survey vermast veralt harmonization cpiperiod cpi ppp icpbase /// + imp_wat_rec imp_san_rec landphone cellphone computer electricity + + noi disp "" _n + + foreach checkvar of local checkvars { + cap confirm var `checkvar' + if _rc { + noi disp as err "Caution:" in y " variable" in w " `checkvar' " /// + in y "not found in dataset" + gen `checkvar' = . + local check`checkvar' = 0 + } + else { + local check`checkvar' = 1 + } + + } // end of checkvars loop + noi disp "" _n + + /*pid*/ + if (`checkpid' == 1 & !missing(pid)) { + sort countrycode year hhid pid + duplicates report countrycode year hhid pid + cap assert r(unique_value) == r(N) + if ("`pid'" != "") { + if _rc { + noi disp as err "variable pid is not unique for combination household/individual." /// + _n "{stata duplicates example countrycode year hhid pid: click here}" /// + " to see examples of duplicated obs." + local flagerr = 1 + } + } + } // end of pid + + //Subnat id checks...need to add shapefile codes + forval z=1/3{ + if (`checksubnatid`z''==1) { + capture confirm string var subnatid`z' + if (_rc) { + noi di as err "Subnatid`z' was not correctly specified. Please, make sure that the following naming convention (string) is used: # – String" + local flagerr =1 + } + cap levelsof subnatid`z', local(mysub) + local mysub1: list sizeof mysub + if (`mysub1'==1 & `"`mysub'"'!="`"."'"){ + noi dis as err "Subnatid`z' is constant for all entries, please revise" + local flagerr =1 + } + } + } + //relationharm + if (`checkrelationharm' == 1) { + cap assert missing(relationharm) + if _rc!=0{ + levelsof relationharm + if wordcount(r(levels)) > 6 { + noi disp as err "relationharm should not have more than 6 numeric values." /// + " It has " wordcount(r(levels)) " values" + local flagerr = 1 + } + + if wordcount(r(levels)) < 6 { + noi disp as err "Caution:" in y " relationharm has less than 6 values." /// + " It has " wordcount(r(levels)) " values" + } + + + ** check only one head per household + sort countrycode year hhid relationharm + tempvar nhh // number of head of the household + bysort hhid: egen `nhh' = total(relationharm == 1) + cap assert `nhh' == 1 | `nhh' == 0 + if _rc { + noi disp as err "There is more than one head per household. " /// + "Please check variable relationharm" + local flagerr = 1 + } + + ** check values + cap assert inrange(relationharm, 1,6) | relationharm == . + if _rc { + noi disp as err "relationharm should not have values outside the range {1,6}" + local flagerr = 1 + } + } + } + //Marital + if (`checkmarital' == 1) { + cap assert missing(marital) + if _rc!=0{ + levelsof marital + if wordcount(r(levels)) > 5 { + noi disp as err "marital should not have more than 5 numeric values." /// + " It has " wordcount(r(levels)) " values" + local flagerr = 1 + } + + cap if wordcount(r(levels)) < 5 { + noi disp as err "Caution:" in y " marital has less than 5 values." + } + + ** check values + cap assert inrange(marital, 1,5) | marital == . + if _rc { + noi disp as err "marital should not have values outside the range {1,5}" + local flagerr = 1 + } + } + } // end of Marital + + //lstatus + if (`checklstatus' == 1) { + cap assert missing(lstatus) + if _rc!=0{ + levelsof lstatus + if wordcount(r(levels)) > 3 { + noi disp as err "lstatus should not have more than 3 numeric values." /// + " It has " wordcount(r(levels)) " values" + local flagerr = 1 + } + ** check values + cap assert inrange(lstatus, 1,3) | lstatus == . + if _rc { + noi disp as err "lstatus should not have values outside the range {1,3}" + local flagerr = 1 + } + + if ("`lstatus'" != "" & "`minlaborage'" != "") { + count if (age < `minlaborage' & lstatus == 1) + if r(N) > 0 & r(N) < . { + noi disp as error "Caution:" in y " you have " in w r(N) in y /// + " underaged individuals (less than `minlaborage' years old) who are employed" + } + } + } + } + + /*empstat */ + if (`checkempstat' == 1) { + + cap assert missing(empstat) + if _rc!=0{ + levelsof empstat + if wordcount(r(levels)) > 5 { + noi disp as err "empstat should not have more than 5 numeric values." /// + " It has " wordcount(r(levels)) " values" + local flagerr = 1 + } + + if wordcount(r(levels)) < 5 { + noi disp as err "Caution:" in y" empstat has less than 5 values." + } + + ** check values + cap assert inrange(empstat, 1,5) | missing(empstat) + if _rc { + noi disp as err "empstat should not have values outside the range {1,5}" + local flagerr = 1 + } + + ** Consistency with other variables. + count if inlist(empstat,3,4) & age < minlaborage + if (r(N)>0 & r(N)<.) { + noi disp as err "Caution: " in y "There are " r(N) " underaged individuals (less than minlaborage) who" /// + " are either employers or self-employed. Please check if this is correct" + } + } + } + +/*industrycat10 */ + if (`checkindustrycat10' == 1) { + cap assert missing(industrycat10) + if _rc!=0{ + levelsof industrycat10 + if wordcount(r(levels)) > 10 { + noi disp as err "industrycat10 should not have more than 10 numeric values." /// + " It has " wordcount(r(levels)) " values" + local flagerr = 1 + } + } + } + +/*industrycat4 */ + if (`checkindustrycat4' == 1) { + cap assert missing(industrycat4) + if _rc!=0{ + levelsof industrycat4 + if wordcount(r(levels)) > 4 { + noi disp as err "industrycat4 should not have more than 4 numeric values." /// + " It has " wordcount(r(levels)) " values" + local flagerr = 1 + } + } + } + +/*school */ + if (`checkschool' == 1) { + cap assert missing(school) + if _rc!=0{ + cap assert inlist(school,0,1) | school == . + if _rc { + noi disp as err "variable school can only take either 0 or 1 as values. Please check" + } + } + } + +/*literacy */ + if (`checkliteracy' == 1) { + cap assert missing(literacy) + if _rc!=0{ + cap assert inlist(literacy,0,1) | literacy == . + if _rc { + noi disp as err "variable literacy can only take either 0 or 1 as values. Please check" + local flagerr = 1 + } + } + } + +/*educy */ + if (`checkeducy' == 1) { + cap assert missing(educy) + if _rc!=0{ + + count if (educy >= age & educy <. & educy != 0 ) + if (r(N)>0 & r(N)<.) { + noi disp as err "educy (years of education) cannot be greater or equal than age." /// + r(N) " Cases" + local flagerr = 1 + } + + count if ( age - educy <= 2 ) + if (r(N)>0 & r(N)<.) { + noi disp as err "Caution:" in y " For " r(N) " obs., educy (years of education) is" /// + " two or less years smaller than current age. Check if this is correct." + } + } + } + +/*educat4 */ + if (`checkeducat4' == 1) { + cap assert missing(educat4) + if _rc!=0{ + levelsof educat4 + if wordcount(r(levels)) > 4 { + noi disp as err "educat4 should not have more than 4 numeric values." /// + " It has " wordcount(r(levels)) " values" + local flagerr = 1 + } + } + } + +/*educat5 */ + if (`checkeducat5' == 1) { + cap assert missing(educat5) + if _rc!=0{ + levelsof educat5 + if wordcount(r(levels)) > 5 { + noi disp as err "educat5 should not have more than 5 numeric values." /// + " It has " wordcount(r(levels)) " values" + local flagerr = 1 + } + } + } + +/*educat7 */ + if (`checkeducat7' == 1) { + cap assert missing(educat7) + if _rc!=0{ + levelsof educat7 + if wordcount(r(levels)) > 7 { + noi disp as err "educat7 should not have more than 7 numeric values." /// + " It has " wordcount(r(levels)) " values" + local flagerr = 1 + } + } + } + +/*Assets */ + if (`checklandphone' == 1) { + cap assert missing(landphone) + if _rc!=0{ + cap assert inlist(landphone,0,1) | landphone == . + if _rc { + noi disp as err "asset can only take either 0 or 1 as values. Please check" + local flagerr = 1 + } + } + } + + if (`checkcellphone' == 1) { + cap assert missing(cellphone) + if _rc!=0{ + cap assert inlist(cellphone,0,1) | cellphone == . + if _rc { + noi disp as err "cellphone can only take either 0 or 1 as values. Please check" + local flagerr = 1 + } + } + } + + if (`checkcomputer' == 1) { + cap asser missing(computer) + if _rc!=0{ + cap assert inlist(computer,0,1) | computer == . + if _rc { + noi disp as err "computer can only take either 0 or 1 as values. Please check" + local flagerr = 1 + } + } + } + + if (`checkelectricity' == 1) { + cap assert missing(electricity) + if _rc!=0{ + cap assert inlist(electricity,0,1) | electricity == . + if _rc { + noi disp as err "electricity can only take either 0 or 1 as values. Please check" + local flagerr = 1 + } + } + } + +/* primarycomp */ + + if (`checkprimarycomp' == 1) { + cap assert missing(primarycomp) + if _rc!=0{ + cap assert inlist(primarycomp,0,1) | primarycomp == . + if _rc { + noi disp as err "primarycomp can only take either 0 or 1 as values. Please check" + local flagerr = 1 + } + } + } + +/* relationcs */ + + if (`checkrelationcs' == 1) { + * This is region specific... + } + +/* Age */ +* GMD 2.0 allows age to be a decimal for individuals <5 yrs + + if (`checkage' == 1) { + cap assert missing(age) + if _rc!=0{ + * integers for individuals older than 5 yrs + cap assert age == int(age) if age>5 + if _rc { + noi disp as err "age must be integers only for age >5 yrs. Please check!" + local flagerr = 1 + } + + cap assert age >= 0 // check age is positive or missing + if _rc { + noi disp as err "age cannot have negative values" + local flagerr = 1 + } + } + } + + +/* Survey */ + + if (`checksurvey' == 1 & !missing(survey)) { + cap assert missing(survey) + if _rc!=0{ + + cap assert regexm(survey,`"[a-zA-Z]+"') + if _rc { + noi disp as err "survey must contain only alphabetic values" + local flagerr = 1 + } + + } + } + + +/* Improved water */ + + if (`checkimp_wat_rec' == 1) { + cap assert missing(imp_wat_rec) + if _rc!=0{ + cap assert inlist(imp_wat_rec,0,1) | imp_wat_rec == . + if _rc { + noi disp as err "imp_wat_rec can only take either 0 or 1 as values. Please check!" + local flagerr = 1 + } + } + } + + +/* Improved sanitation */ + + if (`checkimp_san_rec' == 1) { + cap assert missing(imp_san_rec) + if _rc!=0{ + cap assert inlist(imp_san_rec,0,1) | imp_san_rec == . + if _rc { + noi disp as err "imp_san_rec can only take either 0 or 1 as values. Please check!" + local flagerr = 1 + } + } + } + +/* Landphone */ + + if (`checklandphone' == 1) { + cap assert missing(landphone) + if _rc!=0{ + cap assert inlist(landphone,0,1) | landphone == . + if _rc { + noi disp as err "landphone can only take either 0 or 1 as values. Please check!" + local flagerr = 1 + } + } + } + +/* Cell phone */ + + if (`checkcellphone' == 1) { + cap assert missing(cellphone) + if _rc!=0{ + cap assert inlist(cellphone,0,1) | cellphone == . + if _rc { + noi disp as err "cellphone can only take either 0 or 1 as values. Please check!" + local flagerr = 1 + } + } + } + +/* Computer */ + + if (`checkcomputer' == 1) { + cap assert missing(computer) + if _rc!=0{ + cap assert inlist(computer,0,1) | computer == . + if _rc { + noi disp as err "computer can only take either 0 or 1 as values. Please check!" + local flagerr = 1 + } + } + } + +/* Electricity */ + + if (`checkelectricity' == 1) { + cap assert missing(electricity) + if _rc!=0{ + cap assert inlist(electricity,0,1) | electricity == . + if _rc { + noi disp as err "electricity can only take either 0 or 1 as values. Please check!" + local flagerr = 1 + } + } + } + + +************************************************** + /* label variables and values for GMD database */ + ************************************************** + + cap label var countrycode "WDI three letter country codes " + cap label var year "4 digit year of the survey" + cap label var spdef "Spatial deflator (if one is used)" + cap label var weight_h "Individual weights" + cap label var weight_p "Poverty specific weights" + cap label var weighttype "Weight type (frequency, probability, analytical, importance)" + cap label var cpi "CPI ratio value of survey (rebased to `icpbase' on base 1)" + cap label var cpiperiod "Periodicity of CPI (year, year&month, year&quarter, weighted)" + cap label var ppp "PPP conversion factor. (`icpbase')" + cap label var survey "Type of survey" + cap label var vermast "Version number of master data file" + cap label var veralt "Version number of adaptation to the master data file" + cap label var harmonization "Type of harmonization" + cap label var converfactor "Conversion factor" + cap label var subnatid1 "Subnational ID - highest level" + cap label var subnatid2 "Subnational ID - second highest level" + cap label var subnatid3 "Subnational ID - third highest level" + cap label var strata "Strata" + cap label var psu "PSU" + cap label var welfare "Welfare aggregate used for estimating international poverty (provided to PovcalNet)" + cap label var welfarenom "Welfare aggregate in nominal terms" + cap label var welfaredef "Welfare aggregate spatially deflated" + cap label var welfaretype "Type of welfare measure (income, consumption or expenditure) for welfare, welfarenom, welfaredef" + cap label var welfshprosperity "Welfare aggregate for shared prosperity (if different from poverty)" + cap label var welfshprtype "Welfare type for shared prosperity indicator (income, consumption or expenditure)" + cap label var welfareother "Welfare aggregate if different welfare type is used from welfare, welfarenom, welfaredef" + cap label var welfareothertype "Type of welfare measure (income, consumption or expenditure) for welfareother" + cap label var hsize "Household size" + cap label var hhid "Household ID" + cap label var pid "Individual identifier" + cap label var urban "Urban (1) or rural (0)" + cap label var age "Age of individual (continuous)" + cap label var agecat "Age of individual (categorical)" + cap label var male "Sex of household member (male=1)" + cap label var relationharm "Relationship to head of household harmonized across all regions" + cap label var relationcs "Relationship to head of household country/region specific" + cap label var marital "Marital status" + cap label var lstatus "Labor Force Status" + cap label var minlaborage "Minimum age for employment" + cap label var empstat "Type of employment" + cap label var industrycat4 "Sector/industry of employment (4 categories)" + cap label var industrycat10 "Sector/industry of employment (10 categories)" + cap label var school "Currently in school" + cap label var literacy "Individual can read and write" + cap label var educy "Years of education" + cap label var educat4 "Level of education 4 categories" + cap label var educat5 "Level of education 5 categories" + cap label var educat7 "Level of education 7 categories" + cap label var landphone "Own Landline (fixed) phone" + cap label var cellphone "Own mobile phone (at least one)" + cap label var computer "Own Computer" + cap label var electricity "Access to electricity" + cap label var primarycomp "Primary school completion" + + + ** Keep variables + if (trim(upper("`module'"))=="ALL"){ + local gmdvars `welfare' `weight' `age' `male' `urban' `hhid' `hsize' /// + `strata' `psu' `time' `welfshprosperity' `othervariables' /// + `subnatid1' `spdef' `converfactor' `checkvars' `povweight' + + local varstodrop: list varsindata - gmdvars + if ("`varstodrop'" != "") noi disp in red _n "Caution: " in y /// + "the following variables in your dataset wont be included" /// + " in the `collection' collection:" _n _col(6) in w "`varstodrop'" + + local constantlist weighttype welfaretype welfshprtype weighttype survey vermast /// + veralt harmonization cpiperiod level ref_year + + keep `welfare' weight_h weight_p `age' `male' `urban' `hhid' `hsize' /// + `strata' `psu' `time' `welfshprosperity' `othervariables' /// + `subnatid1' `spdef' `converfactor' `checkvars' + } + +} //END OF GMD VAR CHECKS + +if (`flagerr' == 1) { + noi disp _n(2) as err "There is at least one irreconcilable error in the " /// + "dataset. Data not uploaded." + error 1 + exit +} + +*=============================================================================== +// 8) Map temporary directories and file name +*=============================================================================== +if ("`drive'" == "") local drive E +if (length("`drive'") != 1) { + disp in red "option drive should be a single letter according to the " _n /// + "availability of network locations in your computer. Default is E:\" + error +} + +local netdrive "\\wbntst01.worldbank.org\TeamDisk/`collection'" +if ("`nopovcal'"!="") mapdrive `drive', path(`netdrive') + + ************************************************** + /* path */ + ************************************************** + + if ("`savepath'" == "local") { + local path "c:\data\" + } + if ("`savepath'" != "local") & ("`savepath'" != "") { + local path "`savepath'" + } + if ("`savepath'" == "") { + if ("`nopovcal'"!="") local path "`pathmodule'" + } + + ************************************************** + /* fullname */ + ************************************************** + + if ("`fullname'" != "") { + + local fullname = trim(upper("`fullname'")) + + if !regexm(`"`fullname'"', `"^[A-Z][A-Z][A-Z]_[1-2][0-9][0-9][0-9]_[A-Z0-9\-]+_V0[1-9]_M_V0[1-9]_A_[A-Z0-9\-]+$"') { + noi disp _n in red "full name must be specified in the form " in g /// + "CCC_YYYY_SSS_VXX_M_VYY_A_HHH" in red " where," _n /// + _col(8) in g "CCC: " in w "Country code" _n /// + _col(8) in g "YYYY: " in w "Survey year" _n /// + _col(8) in g "SSS: " in w "Survey Acronym " _n /// + _col(8) in g "XX: " in w "Master two-digit version number" _n /// + _col(8) in g "YY: " in w "Alternative two-digit version number" _n /// + _col(8) in g "HHH: " in w "Harmonization name" + local flagerr = 1 + } + + lstrfun survey, regexms(`"`fullname'"', `"(^.*)_([A-Z]+[-]?[A-Z]+)_V0[1-9]_M(.*)"', 2) + lstrfun vermast, regexms(`"`fullname'"', `"(^.*)_V(0[1-9])_M(.*)"', 2) + lstrfun veralt, regexms(`"`fullname'"', `"(^.*)M_V(0[1-9])_A(.*)"', 2) + lstrfun harmonization, regexms(`"`fullname'"', `"(^.*)_([A-Z0-9\-]+)([_\-]?[0-9]?[0-9]?)$"', 2) + } + + ************************************************** + /* Default|Current directory */ + ************************************************** + + local cpath="`c(pwd)'" + if ("`nopovcal'"!="") cd "`path'" + + confirmdir `countrycode' + if ("`r(confirmdir)'" != "0") { + if ("`nopovcal'"!="") qui mkdir `countrycode' // country level + } + if ("`nopovcal'"!="") cd "`countrycode'" + + + confirmdir `countrycode'_`year'_`survey' + if ("`r(confirmdir)'" != "0") { + if ("`nopovcal'"!="") qui mkdir `countrycode'_`year'_`survey' // survey level + } + if ("`nopovcal'"!="") cd "`countrycode'_`year'_`survey'" + + confirmdir `countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection' // collection level + if ("`r(confirmdir)'" != "0") { + if ("`nopovcal'"!="") qui mkdir `countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection' // collection level + } + if ("`nopovcal'"!="") cd "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'" + + + lstrfun lastdir, regexms(`"`path'"', `"(^.*)\\([a-zA-Z_\-]+)$"', 2) + if ("`restricted'" == "") /* + */ local path "\\wbntst01.worldbank.org\TeamDisk/`collection'/datalib/all_region" // to be fixed. + + if ("`restricted'" == "restricted") /* + */ local path "\\wbntst01.worldbank.org\TeamDisk/`collection'/datalib_restricted-`reg'" // to be fixed. + + local pathcpi "\\wbntst01.worldbank.org\TeamDisk/GMD\datalib" + + cd "`cpath'" // restore original current directory + + cap mapdrive `drive', delete + + *======================================================================== + // FOLDERS FOR OTHER MODULES + *======================================================================== + + if (("`pathmodule'"!="" & "`module'"!="GPWG" & "`module'"!="ALL") | ("`pathmodule'"!="" & "`nopovcal'"!="")) { + if ("`harmonization'" == "NA"){ + local filename = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'_`module'" + local foldername = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'" + } + else { + local filename = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'_`module'" + local foldername = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'" + } + + local filepath = "`pathmodule'\\`countrycode'\\`countrycode'_`year'_`survey'\\`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'" + local filepath2 = "`filepath'" + local filename2 = "`filename'" + return local filepath = "`filepath'" + return local filename = "`filename'" + if ("`module'"!="GPWG" & "`module'"!="ALL" & "`nopovcal'"!=""){ + if ("`replace'"!="") saveold `filepath'/`filename', `replace' + else saveold `filepath'/`filename' + noi dis in green "Your file has been uploaded to:" + noi dis in white "`pathmodule'/`filename'" + exit + } + } + +*=============================================================================== +// 9) Return list and Data Signature +*=============================================================================== +************************************************** +/* Return list */ +************************************************** + +if ("`harmonization'" == "NA"){ + local filename = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'_`module'" + local foldername = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'" +} +else { + local filename = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'_`module'" + local foldername = "`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'" +} +local filepath = "`path'\\`countrycode'\\`countrycode'_`year'_`survey'\\`countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection'" + return local filepath = "`filepath'" + return local filename = "`filename'" + +************************************************** +/* Data signature */ +************************************************** +preserve + cap drop ppp + cap drop cpi + cap drop cpiperiod + datasignature + local datasig = r(datasignature) +restore +*=============================================================================== +// 10) Notes +*=============================================================================== + local date : di %tdN/D/CY date("$S_DATE", "DMY") + local username = c(username) + + if ("`harmonization'"=="NA"){ + note: `date', $S_TIME, `reg', `countrycode', `year', `survey', `harmonization', `username', `countrycode'_`year'_`survey'_V`vermast'_M_`collection', `replace', `surveylevel', `restricted', `savepath' `datasig' + } + else { + note: `date', $S_TIME, `reg', `countrycode', `year', `survey', `harmonization', `username', `countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`harmonization'_`collection', `replace', `surveylevel', `restricted', `savepath' `datasig' + } + + note `if' + note `in' + note `note' + +// extract notes as local to save in external files +local i=1 +while `i'!=. { + if `"`_dta[note`i']'"' != "" { + di `"`i'. `_dta[note`i']'"' + local i = `i' + 1 + } + else { + local i = . + } +} +cap drop __00* +*=============================================================================== +// 11) Check Vintage +*=============================================================================== +noi:dis in green "Foldername: `foldername'" +noi:dis in green "Filename: `filename'" + +*if ((`docheck'==0 | `docheck'==1) & "`collection'"=="GMD"){ +if (`docheck'==1 & "`collection'"=="GMD"){ + + noi: primus_check, country(`countrycode') verm(`vermast') vera(`veralt') year(`year') module(`module') + local replaceok = r(proceed) + + if (`replaceok'==0){ + dis as error "You requested to overwrite data, but your data is different from the one in the system" + error 378665 + exit + } + else{ + local nopovcal=1 + } +} +if ("`nopovcal'"!="") local nopovcal=1 +else local nopovcal=0 +*=============================================================================== +// 12) Send to Primus Up command +*=============================================================================== +if (("`module'"=="ALL"|"`module'"=="GPWG") & "`restricted'"==""){ + noi: primus_up, nopovcal(`nopovcal') output(`output') natcode(`countrycode') year(`year') /// + weflist(`welfare_primus') vermast_p(`vermast') veralt_p(`veralt') surveys(`foldername') /// + ctryname(`primus_cname') filename(`filename') reg(`reg') refyear(`refyear') /// + no_pweight(`no_pweight') povweight(weight_p) filepath(`filepath2') filename(`filename') hhlev(`hhlev') byvar(`byvar') collection(`collection') + + return local primusid = "`e(transid)'" +} +*=============================================================================== +// 13) Log file +*=============================================================================== + + if ("`restricted'" == "") { + local restricted unrestricted + } + + cap file open `hh' using "\\wbntst01.worldbank.org\TeamDisk/`collection'/datalib\_log\log_upload2.csv", write text append + + if ("`harmonization'"=="NA"){ + cap file write `hh' "`date', $S_TIME, `countrycode', `year', `survey', master , `username', V`vermast', V`veralt', NA , `countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`collection', `replace', `surveylevel', `reg', `restricted', `savepath', `path'" _n + } + else { + cap file write `hh' "`date', $S_TIME, `countrycode', `year', `survey', `harmonization', `username', V`vermast', V`veralt', `countrycode'_`year'_`survey'_V`vermast'_M_V`veralt'_A_`harmonization'_`collection', `replace', `surveylevel', `reg', `restricted', `savepath', `path'" _n + } + + cap file close `hh' + + + cd "`cpath'" // restore original current directory + +} // end of Quietly + +if ("`keepdata'" != "") { + use `_tmp', clear +} + +end //END OF PRIMUS UPLOAD!! +************************************************** +/* Program to map temporally drives*/ +************************************************** + +cap program drop mapdrive +program define mapdrive + syntax anything(name=drive), [path(string) delete] + local drive = upper("`drive'") + shell net use /del `drive': /Y + if ("`delete'" == "") shell net use `drive': `path' /PERSISTENT:no +end + + +*=============================================================================== +//Program for countrynames +*=============================================================================== + + +cap program drop _countryname +program define _countryname + +qui { + tempname n + tempfile names + + postfile `n' str3(region countrycode) str30 countryname using `names' , replace + + * postfile `n' str3(region countrycode) str30 countryname using countrynames , replace + + post `n' ("EAP") ("ASM") ("American Samoa") + post `n' ("EAP") ("AUS") ("Australia") + post `n' ("EAP") ("BRN") ("Brunei Darussalam") + post `n' ("EAP") ("CHN") ("China") + post `n' ("EAP") ("FJI") ("Fiji") + post `n' ("EAP") ("FSM") ("Micronesia, Fed. Sts.") + post `n' ("EAP") ("GUM") ("Guam") +* post `n' ("EAP") ("HKG") ("Hong Kong SAR, China") + post `n' ("EAP") ("IDN") ("Indonesia") + post `n' ("EAP") ("JPN") ("Japan") + post `n' ("EAP") ("KHM") ("Cambodia") + post `n' ("EAP") ("KIR") ("Kiribati") + post `n' ("EAP") ("KOR") ("Korea, Rep.") + post `n' ("EAP") ("LAO") ("Lao PDR") +* post `n' ("EAP") ("MAC") ("Macao SAR, China") + post `n' ("EAP") ("MHL") ("Marshall Islands") + post `n' ("EAP") ("MMR") ("Myanmar") + post `n' ("EAP") ("MNG") ("Mongolia") + post `n' ("EAP") ("MNP") ("Northern Mariana Islands") + post `n' ("EAP") ("MYS") ("Malaysia") + post `n' ("EAP") ("NCL") ("New Caledonia") + post `n' ("EAP") ("NRU") ("Nauru") + post `n' ("EAP") ("NZL") ("New Zealand") + post `n' ("EAP") ("PHL") ("Philippines") + post `n' ("EAP") ("PLW") ("Palau") + post `n' ("EAP") ("PNG") ("Papua New Guinea") +* post `n' ("EAP") ("PRK") ("Korea, Dem. People's Rep.") + post `n' ("EAP") ("PYF") ("French Polynesia") + post `n' ("EAP") ("SGP") ("Singapore") + post `n' ("EAP") ("SLB") ("Solomon Islands") + post `n' ("EAP") ("THA") ("Thailand") + post `n' ("EAP") ("TLS") ("Timor-Leste") + post `n' ("EAP") ("TON") ("Tonga") + post `n' ("EAP") ("TUV") ("Tuvalu") +* post `n' ("EAP") ("TWN") ("Taiwan, China") + post `n' ("EAP") ("VNM") ("Vietnam") + post `n' ("EAP") ("VUT") ("Vanuatu") + post `n' ("EAP") ("WSM") ("Samoa") + post `n' ("ECA") ("ALB") ("Albania") + post `n' ("ECA") ("AND") ("Andorra") + post `n' ("ECA") ("ARM") ("Armenia") + post `n' ("ECA") ("AUT") ("Austria") + post `n' ("ECA") ("AZE") ("Azerbaijan") + post `n' ("ECA") ("BEL") ("Belgium") + post `n' ("ECA") ("BGR") ("Bulgaria") + post `n' ("ECA") ("BIH") ("Bosnia and Herzegovina") + post `n' ("ECA") ("BLR") ("Belarus") + post `n' ("ECA") ("CHE") ("Switzerland") + post `n' ("ECA") ("CHI") ("Channel Islands") + post `n' ("ECA") ("CYP") ("Cyprus") + post `n' ("ECA") ("CZE") ("Czech Republic") + post `n' ("ECA") ("DEU") ("Germany") + post `n' ("ECA") ("DNK") ("Denmark") + post `n' ("ECA") ("ESP") ("Spain") + post `n' ("ECA") ("EST") ("Estonia") + post `n' ("ECA") ("FIN") ("Finland") + post `n' ("ECA") ("FRA") ("France") + post `n' ("ECA") ("FRO") ("Faroe Islands") + post `n' ("ECA") ("GBR") ("United Kingdom") + post `n' ("ECA") ("GEO") ("Georgia") + post `n' ("ECA") ("GIB") ("Gibraltar") + post `n' ("ECA") ("GRC") ("Greece") + post `n' ("ECA") ("GRL") ("Greenland") + post `n' ("ECA") ("HRV") ("Croatia") + post `n' ("ECA") ("HUN") ("Hungary") + post `n' ("ECA") ("IMN") ("Isle of Man") + post `n' ("ECA") ("IRL") ("Ireland") + post `n' ("ECA") ("ISL") ("Iceland") + post `n' ("ECA") ("ITA") ("Italy") + post `n' ("ECA") ("KAZ") ("Kazakhstan") + post `n' ("ECA") ("KGZ") ("Kyrgyz Republic") + post `n' ("ECA") ("KSV") ("Kosovo") + post `n' ("ECA") ("LIE") ("Liechtenstein") + post `n' ("ECA") ("LTU") ("Lithuania") + post `n' ("ECA") ("LUX") ("Luxembourg") + post `n' ("ECA") ("LVA") ("Latvia") + post `n' ("ECA") ("MCO") ("Monaco") + post `n' ("ECA") ("MDA") ("Moldova") + post `n' ("ECA") ("MKD") ("Macedonia, FYR") + post `n' ("ECA") ("MNE") ("Montenegro") + post `n' ("ECA") ("NLD") ("Netherlands") + post `n' ("ECA") ("NOR") ("Norway") + post `n' ("ECA") ("POL") ("Poland") + post `n' ("ECA") ("PRT") ("Portugal") + post `n' ("ECA") ("ROU") ("Romania") + post `n' ("ECA") ("RUS") ("Russian Federation") + post `n' ("ECA") ("SMR") ("San Marino") + post `n' ("ECA") ("SRB") ("Serbia") + post `n' ("ECA") ("SVK") ("Slovak Republic") + post `n' ("ECA") ("SVN") ("Slovenia") + post `n' ("ECA") ("SWE") ("Sweden") + post `n' ("ECA") ("TJK") ("Tajikistan") + post `n' ("ECA") ("TKM") ("Turkmenistan") + post `n' ("ECA") ("TUR") ("Turkey") + post `n' ("ECA") ("UKR") ("Ukraine") + post `n' ("ECA") ("UZB") ("Uzbekistan") + post `n' ("LAC") ("ABW") ("Aruba") + post `n' ("LAC") ("ARG") ("Argentina") + post `n' ("LAC") ("ATG") ("Antigua and Barbuda") + post `n' ("LAC") ("BHS") ("Bahamas, The") + post `n' ("LAC") ("BLZ") ("Belize") + post `n' ("LAC") ("BOL") ("Bolivia") + post `n' ("LAC") ("BRA") ("Brazil") + post `n' ("LAC") ("BRB") ("Barbados") + post `n' ("LAC") ("CHL") ("Chile") + post `n' ("LAC") ("COL") ("Colombia") + post `n' ("LAC") ("CRI") ("Costa Rica") + post `n' ("LAC") ("CUB") ("Cuba") + post `n' ("LAC") ("CUW") ("Curaçao") + post `n' ("LAC") ("CYM") ("Cayman Islands") + post `n' ("LAC") ("DMA") ("Dominica") + post `n' ("LAC") ("DOM") ("Dominican Republic") + post `n' ("LAC") ("ECU") ("Ecuador") + post `n' ("LAC") ("GRD") ("Grenada") + post `n' ("LAC") ("GTM") ("Guatemala") + post `n' ("LAC") ("GUY") ("Guyana") + post `n' ("LAC") ("HND") ("Honduras") + post `n' ("LAC") ("HTI") ("Haiti") + post `n' ("LAC") ("JAM") ("Jamaica") + post `n' ("LAC") ("KNA") ("St. Kitts and Nevis") + post `n' ("LAC") ("LCA") ("St. Lucia") + post `n' ("LAC") ("MAF") ("St. Martin (French part)") + post `n' ("LAC") ("MEX") ("Mexico") + post `n' ("LAC") ("NIC") ("Nicaragua") + post `n' ("LAC") ("PAN") ("Panama") + post `n' ("LAC") ("PER") ("Peru") + post `n' ("LAC") ("PRI") ("Puerto Rico") + post `n' ("LAC") ("PRY") ("Paraguay") + post `n' ("LAC") ("SLV") ("El Salvador") + post `n' ("LAC") ("SUR") ("Suriname") + post `n' ("LAC") ("SXM") ("Sint Maarten (Dutch part)") + post `n' ("LAC") ("TCA") ("Turks and Caicos Islands") + post `n' ("LAC") ("TTO") ("Trinidad and Tobago") + post `n' ("LAC") ("URY") ("Uruguay") + post `n' ("LAC") ("VCT") ("St. Vincent and the Grenadines") + post `n' ("LAC") ("VEN") ("Venezuela, RB") + post `n' ("LAC") ("VGB") ("British Virgin Islands") + post `n' ("LAC") ("VIR") ("Virgin Islands (U.S.)") + post `n' ("MNA") ("ARE") ("United Arab Emirates") + post `n' ("MNA") ("BHR") ("Bahrain") + post `n' ("MNA") ("DJI") ("Djibouti") + post `n' ("MNA") ("DZA") ("Algeria") + post `n' ("MNA") ("EGY") ("Egypt, Arab Rep.") + post `n' ("MNA") ("IRN") ("Iran, Islamic Rep.") + post `n' ("MNA") ("IRQ") ("Iraq") + post `n' ("MNA") ("ISR") ("Israel") + post `n' ("MNA") ("JOR") ("Jordan") + post `n' ("MNA") ("KWT") ("Kuwait") + post `n' ("MNA") ("LBN") ("Lebanon") + post `n' ("MNA") ("LBY") ("Libya") + post `n' ("MNA") ("MAR") ("Morocco") + post `n' ("MNA") ("MLT") ("Malta") + post `n' ("MNA") ("OMN") ("Oman") + post `n' ("MNA") ("PSE") ("West Bank and Gaza") + post `n' ("MNA") ("QAT") ("Qatar") + post `n' ("MNA") ("SAU") ("Saudi Arabia") + post `n' ("MNA") ("SYR") ("Syrian Arab Republic") + post `n' ("MNA") ("TUN") ("Tunisia") + post `n' ("MNA") ("YEM") ("Yemen, Rep.") + post `n' ("NAC") ("BMU") ("Bermuda") + post `n' ("NAC") ("CAN") ("Canada") + post `n' ("NAC") ("USA") ("United States") + post `n' ("SAR") ("AFG") ("Afghanistan") + post `n' ("SAR") ("BGD") ("Bangladesh") + post `n' ("SAR") ("BTN") ("Bhutan") + post `n' ("SAR") ("IND") ("India") + post `n' ("SAR") ("LKA") ("Sri Lanka") + post `n' ("SAR") ("MDV") ("Maldives") + post `n' ("SAR") ("NPL") ("Nepal") + post `n' ("SAR") ("PAK") ("Pakistan") + post `n' ("SSA") ("AGO") ("Angola") + post `n' ("SSA") ("BDI") ("Burundi") + post `n' ("SSA") ("BEN") ("Benin") + post `n' ("SSA") ("BFA") ("Burkina Faso") + post `n' ("SSA") ("BWA") ("Botswana") + post `n' ("SSA") ("CAF") ("Central African Republic") + post `n' ("SSA") ("CIV") ("Côte dIvoire") + post `n' ("SSA") ("CMR") ("Cameroon") + post `n' ("SSA") ("COD") ("Congo, Dem. Rep.") + post `n' ("SSA") ("COG") ("Congo, Rep.") + post `n' ("SSA") ("COM") ("Comoros") + post `n' ("SSA") ("CPV") ("Cabo Verde") + post `n' ("SSA") ("ERI") ("Eritrea") + post `n' ("SSA") ("ETH") ("Ethiopia") + post `n' ("SSA") ("GAB") ("Gabon") + post `n' ("SSA") ("GHA") ("Ghana") + post `n' ("SSA") ("GIN") ("Guinea") + post `n' ("SSA") ("GMB") ("Gambia, The") + post `n' ("SSA") ("GNB") ("Guinea-Bissau") + post `n' ("SSA") ("GNQ") ("Equatorial Guinea") + post `n' ("SSA") ("KEN") ("Kenya") + post `n' ("SSA") ("LBR") ("Liberia") + post `n' ("SSA") ("LSO") ("Lesotho") + post `n' ("SSA") ("MDG") ("Madagascar") + post `n' ("SSA") ("MLI") ("Mali") + post `n' ("SSA") ("MOZ") ("Mozambique") + post `n' ("SSA") ("MRT") ("Mauritania") + post `n' ("SSA") ("MUS") ("Mauritius") + post `n' ("SSA") ("MWI") ("Malawi") + post `n' ("SSA") ("NAM") ("Namibia") + post `n' ("SSA") ("NER") ("Niger") + post `n' ("SSA") ("NGA") ("Nigeria") + post `n' ("SSA") ("RWA") ("Rwanda") + post `n' ("SSA") ("SDN") ("Sudan") + post `n' ("SSA") ("SEN") ("Senegal") + post `n' ("SSA") ("SLE") ("Sierra Leone") + post `n' ("SSA") ("SOM") ("Somalia") + post `n' ("SSA") ("SSD") ("South Sudan") + post `n' ("SSA") ("STP") ("São Tomé and Principe") + post `n' ("SSA") ("SWZ") ("Swaziland") + post `n' ("SSA") ("SYC") ("Seychelles") + post `n' ("SSA") ("TCD") ("Chad") + post `n' ("SSA") ("TGO") ("Togo") + post `n' ("SSA") ("TZA") ("Tanzania") + post `n' ("SSA") ("UGA") ("Uganda") + post `n' ("SSA") ("ZAF") ("South Africa") + post `n' ("SSA") ("ZMB") ("Zambia") + post `n' ("SSA") ("ZWE") ("Zimbabwe") + + postclose `n' + + use `names', clear + label var region "Region" + label var countrycode "Country Code" + label var countryname "Country Name" + + compress +} + +end diff --git a/p/primus_upload.sthlp b/primus_upload.sthlp similarity index 97% rename from p/primus_upload.sthlp rename to primus_upload.sthlp index eb41930..55a5c5c 100644 --- a/p/primus_upload.sthlp +++ b/primus_upload.sthlp @@ -1,347 +1,347 @@ -{smcl} -{* *! version 0.0.1 19Jan2018}{...} -{cmd:help primus_upload} -{hline} - -{title:Title} - -{p2colset 5 24 26 2}{...} -{p2col :}{cmd:primus_upload} {hline 1} Submits GMD collection files -{p2colreset}{...} - -{marker syntax}{...} -{title:Syntax} - -{p 8 17 2} -{cmdab:primus_upload} -{ifin} -{cmd:,} -{opt c:ountrycode(string)} {opt y:ear(string)} {opt welf:are(varname)} welfaretype(string) {opt welfsh:prosperity(varname)} welfshprtype(string) weight(varname) weighttype(string) {opt hs:ize(varname)} hhid(varname) {opt mod:ule(string)} {opt sur:vey(string)} [{it:options}] - -{synoptline} -{p2colreset}{...} - -{marker description}{...} -{title:Description} - -{pstd} -{cmd:primus_upload} deposits data files for the Global Monitoring Database (GMD) to calculate poverty statistics through Primus. Users must be have access rights to the server for this command to work. - -{marker options}{...} -{title:Options} - -{dlgtab:Optional} - - -{synopt:{opth povw:eight(varname)}}Weights to be used for poverty calculation, if left empty, the variable specified in the weight option will be used for poverty calculations {p_end} -{synopt:{opth drive(string)}}Drive to which user has mapped the team's disk where data is stored{p_end} -{synopt:{opth sub:natid1(varname)}}Variable indicating regions for highest level of representativeness of survey{p_end} -{synopt:{opth spdef(varname)}}Variable containing spatial adjustment factor{p_end} -{synopt:{opth t:ime(varname)}}Time variable indicating ??? {p_end} -{synopt:{opth welfarenom(varname)}}Variable containing nominal welfare{p_end} -{synopt:{opth welfaredef(varname)}}Variable containing deflated welfare{p_end} -{synopt:{opth welfareother(varname)}}Variable containing other welfare type{p_end} -{synopt:{opth welfareothertype(string)}}Detail on nature of other welfare variable included{p_end} -{synopt:{opth age(varname)}}Variable containing age variable{p_end} -{synopt:{opth male(varname)}}Variable containing male indicator{p_end} -{synopt:{opth urb:an(varname)}}Variable containing urban location{p_end} -{synopt:{opth tfood(varname)}}Variable containing total food expenditure{p_end} -{synopt:{opth tnfood(varname)}}Variable containing total non-food expenfiture{p_end} -{synopt:{opth rent(varname)}}Variable containing rent expenditure{p_end} -{synopt:{opth durgood(varname)}}Variable containing durable good expenditure{p_end} -{synopt:{opth health(varname)}}Variable containing health expenditure{p_end} -{synopt:{opth verm:ast(string)}}version of survey (2 digits), option is NOT overriden if autoversion option is specified{p_end} -{synopt:{opth har:monization(string)}}harmonization name or code{p_end} -{synopt:{opth vera:lt(string)}}Harmonization version number (2 digits), option is overriden if autoversion option is specified{p_end} -{synopt:{opth fullname(string)}}Final data set name to be applied: CCC_YYYY_SSS_VXX_M_VYY_A_HHH{p_end} -{synopt:{opth conver:factor(varname)}}Variable to be included in final data as conversion factor{p_end} -{synopt:{opth othervariables(varlist)}}Extra variables to be included into final dataset{p_end} -{synopt:{opth strata(varname)}}Strata variable{p_end} -{synopt:{opth psu(varname)}}Primary sampling unit variable{p_end} -{synopt:{opth note(string)}}Note to be added to data{p_end} -{synopt:{opth savep:ath(string)}}Directory path for saving files{p_end} -{synopt:{opth icp:base(string)}}Year for PPP conversions{p_end} -{synopt:{opt save13}}Requests data sets to be saved as Stata version 13{p_end} -{synopt:{opt restricted}}Specifies that data is restricted and will not be uploaded to Primus, and will be sent to special folder{p_end} -{synopt:{opt nopov:cal}}Will save data to pre-defined folder and will not be sent to PovCalNet{p_end} -{synopt:{opt replace}}Adds replace option to overwrite previous data with same name{p_end} -{synopt:{opt level(varname)}}Level variable of the PPP variable{p_end} -{synopt:{opt output(string)}}Path to save primus excel information{p_end} -{synopt:{opt welfare_primus(string)}}Primus specific welfare, if empty will take welfare variable{p_end} -{synopt:{opt ref:year(string)}}Specifies reference survey year. If left blank, the value from the year() option is used.{p_end} -{synopt:{opt auto:version}}Auto version control for data. If vermast() is not specified the same vintage as the one from previous version will be used. For new datapoints, both vermast() and veralt() will be equal to 1 {p_end} -{synopt:{opt overwrite}}Allows for replacement of existing vintages. The data is checked for consistency and only addition of new variables is allowed. {p_end} - -{dlgtab:Required} - - -{phang} -{opth countrycode(string)} specifies the three letter country code. See the Remarks section below for a {help upload##codes:list of WDI country codes}. - -{phang} -{opth year(string)} specifies the four digit year (YYYY) in which the survey interviews were conducted for this data file. -If this period spans two years (e.g. 2012-2013), specify the year with the greater number of months for the survey data collection, -or if the number of months are equal (e.g. 6 months in first year and 6 months in second year) specify the more recent year. -OR year of the first day of the interviews. - -{phang} -{opth welfaretype(string)} specifies the type of welfare measure for {cmd: welfare(varname)}. Accepted values are: {bf:INC} for income, {bf:CONS} for consumption, or {bf:EXP} for expenditure. - -{phang} -{opth welfare(varname)} specifies {it:varname} for the welfare variable (e.g. per capita consumption) in the data file. This variable should be in {bf:LCU at current prices}. - -{phang} -{opth weight(varname)} specifies {it:varname} for the survey weight in the data file. - -{phang} -{opth weighttype(string)} specifies the type of weight for {cmd: weight(varname)}. Accepted values are: {bf:FW} for frequency weights, or {bf:PW} for probability weights. - -{phang} -{opth hsize(string)} specifies {it:varname} for household size. - -{phang} -{opth hhid(varname)} specifies {it:varname} for the unique household identification number in the data file. - -{phang} -{opth ppp(varname)} specifies {it:varname} for the PPP conversion factor from the 2011 ICP for year 2011 in the data file; this must be a constant. - -{phang} -{opth cpi(varname)} specifies {it:varname} for the temporal price adjustment factor with respect to the ppp specified period. - -{phang} -{opth cpiperiod(string)} period that the CPI value covers. - -{phang} -{opth module(string)} Module that is being uploaded, if user specifies "ALL", or "GPWG" the data will be sent to the Primus approval process. - -{marker examples}{...} -{title:Examples} - -{phang}{cmd:. primus, countrycode(GEO) year(2015) welfare(gallT) welfaretype(CONS) welfshprosperity(gallT2) welfshprtype(CONS) weight(weight1) weighttype(FW) hsize(hhsize) hhid(hhid1) cpi(cpi2011) cpiperiod(year) ppp(icp2011) welfaredef(gallT) urban(urb) survey("`surveys'") vermast("`vermast_p'") harmonization(ECAPOV) veralt("`veralt_p'") othervariables(quarter gallT2) icpbase(2011) save13 savepath(\\wbntst01.worldbank.org\TeamDisk\GPWG\datalib\all_region) module(GPWG) output(\\Ecafile\eca-special\ECA_Databank\ECAPOVII\On_demand\GPWG\test.xlsx)} {p_end} - -{marker remarks}{...} -{title:Remarks} - -{marker codes}{...} -{pstd} -WDI three letter country codes: - -{space 6}{bf:Country}{col 41}{bf:Code} -{space 6}{hline 38} -{space 6}Afghanistan{col 41}AFG -{space 6}Albania {col 41}ALB -{space 6}Algeria {col 41}DZA -{space 6}American Samoa {col 41}ASM -{space 6}Andorra {col 41}ADO -{space 6}Angola {col 41}AGO -{space 6}Antigua and Barbuda {col 41}ATG -{space 6}Argentina {col 41}ARG -{space 6}Armenia {col 41}ARM -{space 6}Aruba {col 41}ABW -{space 6}Australia {col 41}AUS -{space 6}Austria {col 41}AUT -{space 6}Azerbaijan {col 41}AZE -{space 6}Bahamas, The {col 41}BHS -{space 6}Bahrain {col 41}BHR -{space 6}Bangladesh {col 41}BGD -{space 6}Barbados {col 41}BRB -{space 6}Belarus {col 41}BLR -{space 6}Belgium {col 41}BEL -{space 6}Belize {col 41}BLZ -{space 6}Benin {col 41}BEN -{space 6}Bermuda {col 41}BMU -{space 6}Bhutan {col 41}BTN -{space 6}Bolivia {col 41}BOL -{space 6}Bosnia and Herzegovina {col 41}BIH -{space 6}Botswana {col 41}BWA -{space 6}Brazil {col 41}BRA -{space 6}Brunei Darussalam {col 41}BRN -{space 6}Bulgaria {col 41}BGR -{space 6}Burkina Faso {col 41}BFA -{space 6}Burundi {col 41}BDI -{space 6}Cambodia {col 41}KHM -{space 6}Cameroon {col 41}CMR -{space 6}Canada {col 41}CAN -{space 6}Cape Verde {col 41}CPV -{space 6}Cayman Islands {col 41}CYM -{space 6}Central African Republic {col 41}CAF -{space 6}Chad {col 41}TCD -{space 6}Channel Islands {col 41}CHI -{space 6}Chile {col 41}CHL -{space 6}China {col 41}CHN -{space 6}Colombia {col 41}COL -{space 6}Comoros {col 41}COM -{space 6}Congo, Dem. Rep. {col 41}ZAR -{space 6}Congo, Rep. {col 41}COG -{space 6}Costa Rica {col 41}CRI -{space 6}Côte d'Ivoire {col 41}CIV -{space 6}Croatia {col 41}HRV -{space 6}Cuba {col 41}CUB -{space 6}Curaçao {col 41}CUW -{space 6}Cyprus {col 41}CYP -{space 6}Czech Republic {col 41}CZE -{space 6}Denmark {col 41}DNK -{space 6}Djibouti {col 41}DJI -{space 6}Dominica {col 41}DMA -{space 6}Dominican Republic {col 41}DOM -{space 6}Ecuador {col 41}ECU -{space 6}Egypt, Arab Rep. {col 41}EGY -{space 6}El Salvador {col 41}SLV -{space 6}Equatorial Guinea {col 41}GNQ -{space 6}Eritrea {col 41}ERI -{space 6}Estonia {col 41}EST -{space 6}Ethiopia {col 41}ETH -{space 6}Faeroe Islands {col 41}FRO -{space 6}Fiji {col 41}FJI -{space 6}Finland {col 41}FIN -{space 6}France {col 41}FRA -{space 6}French Polynesia {col 41}PYF -{space 6}Gabon {col 41}GAB -{space 6}Gambia, The {col 41}GMB -{space 6}Georgia {col 41}GEO -{space 6}Germany {col 41}DEU -{space 6}Ghana {col 41}GHA -{space 6}Greece {col 41}GRC -{space 6}Greenland {col 41}GRL -{space 6}Grenada {col 41}GRD -{space 6}Guam {col 41}GUM -{space 6}Guatemala {col 41}GTM -{space 6}Guinea {col 41}GIN -{space 6}Guinea-Bissau {col 41}GNB -{space 6}Guyana {col 41}GUY -{space 6}Haiti {col 41}HTI -{space 6}Honduras {col 41}HND -{space 6}Hong Kong SAR, China {col 41}HKG -{space 6}Hungary {col 41}HUN -{space 6}Iceland {col 41}ISL -{space 6}India {col 41}IND -{space 6}Indonesia {col 41}IDN -{space 6}Iran, Islamic Rep. {col 41}IRN -{space 6}Iraq {col 41}IRQ -{space 6}Ireland {col 41}IRL -{space 6}Isle of Man {col 41}IMY -{space 6}Israel {col 41}ISR -{space 6}Italy {col 41}ITA -{space 6}Jamaica {col 41}JAM -{space 6}Japan {col 41}JPN -{space 6}Jordan {col 41}JOR -{space 6}Kazakhstan {col 41}KAZ -{space 6}Kenya {col 41}KEN -{space 6}Kiribati {col 41}KIR -{space 6}Korea, Dem. Rep. {col 41}PRK -{space 6}Korea, Rep. {col 41}KOR -{space 6}Kosovo {col 41}KSV -{space 6}Kuwait {col 41}KWT -{space 6}Kyrgyz Republic {col 41}KGZ -{space 6}Lao PDR {col 41}LAO -{space 6}Latvia {col 41}LVA -{space 6}Lebanon {col 41}LBN -{space 6}Lesotho {col 41}LSO -{space 6}Liberia {col 41}LBR -{space 6}Libya {col 41}LBY -{space 6}Liechtenstein {col 41}LIE -{space 6}Lithuania {col 41}LTU -{space 6}Luxembourg {col 41}LUX -{space 6}Macao SAR, China {col 41}MAC -{space 6}Macedonia, FYR {col 41}MKD -{space 6}Madagascar {col 41}MDG -{space 6}Malawi {col 41}MWI -{space 6}Malaysia {col 41}MYS -{space 6}Maldives {col 41}MDV -{space 6}Mali {col 41}MLI -{space 6}Malta {col 41}MLT -{space 6}Marshall Islands {col 41}MHL -{space 6}Mauritania {col 41}MRT -{space 6}Mauritius {col 41}MUS -{space 6}Mexico {col 41}MEX -{space 6}Micronesia, Fed. Sts. {col 41}FSM -{space 6}Moldova {col 41}MDA -{space 6}Monaco {col 41}MCO -{space 6}Mongolia {col 41}MNG -{space 6}Montenegro {col 41}MNE -{space 6}Morocco {col 41}MAR -{space 6}Mozambique {col 41}MOZ -{space 6}Myanmar {col 41}MMR -{space 6}Namibia {col 41}NAM -{space 6}Nepal {col 41}NPL -{space 6}Netherlands {col 41}NLD -{space 6}New Caledonia {col 41}NCL -{space 6}New Zealand {col 41}NZL -{space 6}Nicaragua {col 41}NIC -{space 6}Niger {col 41}NER -{space 6}Nigeria {col 41}NGA -{space 6}Northern Mariana Islands {col 41}MNP -{space 6}Norway {col 41}NOR -{space 6}Oman {col 41}OMN -{space 6}Pakistan {col 41}PAK -{space 6}Palau {col 41}PLW -{space 6}Panama {col 41}PAN -{space 6}Papua New Guinea {col 41}PNG -{space 6}Paraguay {col 41}PRY -{space 6}Peru {col 41}PER -{space 6}Philippines {col 41}PHL -{space 6}Poland {col 41}POL -{space 6}Portugal {col 41}PRT -{space 6}Puerto Rico {col 41}PRI -{space 6}Qatar {col 41}QAT -{space 6}Romania {col 41}ROM -{space 6}Russian Federation {col 41}RUS -{space 6}Rwanda {col 41}RWA -{space 6}Samoa {col 41}WSM -{space 6}San Marino {col 41}SMR -{space 6}São Tomé and Principe {col 41}STP -{space 6}Saudi Arabia {col 41}SAU -{space 6}Senegal {col 41}SEN -{space 6}Serbia {col 41}SRB -{space 6}Seychelles {col 41}SYC -{space 6}Sierra Leone {col 41}SLE -{space 6}Singapore {col 41}SGP -{space 6}Sint Maarten (Dutch part) {col 41}SXM -{space 6}Slovak Republic {col 41}SVK -{space 6}Slovenia {col 41}SVN -{space 6}Solomon Islands {col 41}SLB -{space 6}Somalia {col 41}SOM -{space 6}South Africa {col 41}ZAF -{space 6}South Sudan {col 41}SSD -{space 6}Spain {col 41}ESP -{space 6}Sri Lanka {col 41}LKA -{space 6}St. Kitts and Nevis {col 41}KNA -{space 6}St. Lucia {col 41}LCA -{space 6}St. Martin (French part) {col 41}MAF -{space 6}St. Vincent and the Grenadines {col 41}VCT -{space 6}Sudan {col 41}SDN -{space 6}Suriname {col 41}SUR -{space 6}Swaziland {col 41}SWZ -{space 6}Sweden {col 41}SWE -{space 6}Switzerland {col 41}CHE -{space 6}Syrian Arab Republic {col 41}SYR -{space 6}Tajikistan {col 41}TJK -{space 6}Tanzania {col 41}TZA -{space 6}Thailand {col 41}THA -{space 6}Timor-Leste {col 41}TMP -{space 6}Togo {col 41}TGO -{space 6}Tonga {col 41}TON -{space 6}Trinidad and Tobago {col 41}TTO -{space 6}Tunisia {col 41}TUN -{space 6}Turkey {col 41}TUR -{space 6}Turkmenistan {col 41}TKM -{space 6}Turks and Caicos Islands {col 41}TCA -{space 6}Tuvalu {col 41}TUV -{space 6}Uganda {col 41}UGA -{space 6}Ukraine {col 41}UKR -{space 6}United Arab Emirates {col 41}ARE -{space 6}United Kingdom {col 41}GBR -{space 6}United States {col 41}USA -{space 6}Uruguay {col 41}URY -{space 6}Uzbekistan {col 41}UZB -{space 6}Vanuatu {col 41}VUT -{space 6}Venezuela, RB {col 41}VEN -{space 6}Vietnam {col 41}VNM -{space 6}Virgin Islands (U.S.) {col 41}VIR -{space 6}West Bank and Gaza {col 41}WBG -{space 6}Yemen, Rep. {col 41}YEM -{space 6}Zambia {col 41}ZMB -{space 6}Zimbabwe {col 41}ZWE - - - +{smcl} +{* *! version 0.0.1 19Jan2018}{...} +{cmd:help primus_upload} +{hline} + +{title:Title} + +{p2colset 5 24 26 2}{...} +{p2col :}{cmd:primus_upload} {hline 1} Submits GMD collection files +{p2colreset}{...} + +{marker syntax}{...} +{title:Syntax} + +{p 8 17 2} +{cmdab:primus_upload} +{ifin} +{cmd:,} +{opt c:ountrycode(string)} {opt y:ear(string)} {opt welf:are(varname)} welfaretype(string) {opt welfsh:prosperity(varname)} welfshprtype(string) weight(varname) weighttype(string) {opt hs:ize(varname)} hhid(varname) {opt mod:ule(string)} {opt sur:vey(string)} [{it:options}] + +{synoptline} +{p2colreset}{...} + +{marker description}{...} +{title:Description} + +{pstd} +{cmd:primus_upload} deposits data files for the Global Monitoring Database (GMD) to calculate poverty statistics through Primus. Users must be have access rights to the server for this command to work. + +{marker options}{...} +{title:Options} + +{dlgtab:Optional} + + +{synopt:{opth povw:eight(varname)}}Weights to be used for poverty calculation, if left empty, the variable specified in the weight option will be used for poverty calculations {p_end} +{synopt:{opth drive(string)}}Drive to which user has mapped the team's disk where data is stored{p_end} +{synopt:{opth sub:natid1(varname)}}Variable indicating regions for highest level of representativeness of survey{p_end} +{synopt:{opth spdef(varname)}}Variable containing spatial adjustment factor{p_end} +{synopt:{opth t:ime(varname)}}Time variable indicating ??? {p_end} +{synopt:{opth welfarenom(varname)}}Variable containing nominal welfare{p_end} +{synopt:{opth welfaredef(varname)}}Variable containing deflated welfare{p_end} +{synopt:{opth welfareother(varname)}}Variable containing other welfare type{p_end} +{synopt:{opth welfareothertype(string)}}Detail on nature of other welfare variable included{p_end} +{synopt:{opth age(varname)}}Variable containing age variable{p_end} +{synopt:{opth male(varname)}}Variable containing male indicator{p_end} +{synopt:{opth urb:an(varname)}}Variable containing urban location{p_end} +{synopt:{opth tfood(varname)}}Variable containing total food expenditure{p_end} +{synopt:{opth tnfood(varname)}}Variable containing total non-food expenfiture{p_end} +{synopt:{opth rent(varname)}}Variable containing rent expenditure{p_end} +{synopt:{opth durgood(varname)}}Variable containing durable good expenditure{p_end} +{synopt:{opth health(varname)}}Variable containing health expenditure{p_end} +{synopt:{opth verm:ast(string)}}version of survey (2 digits), option is NOT overriden if autoversion option is specified{p_end} +{synopt:{opth har:monization(string)}}harmonization name or code{p_end} +{synopt:{opth vera:lt(string)}}Harmonization version number (2 digits), option is overriden if autoversion option is specified{p_end} +{synopt:{opth fullname(string)}}Final data set name to be applied: CCC_YYYY_SSS_VXX_M_VYY_A_HHH{p_end} +{synopt:{opth conver:factor(varname)}}Variable to be included in final data as conversion factor{p_end} +{synopt:{opth othervariables(varlist)}}Extra variables to be included into final dataset{p_end} +{synopt:{opth strata(varname)}}Strata variable{p_end} +{synopt:{opth psu(varname)}}Primary sampling unit variable{p_end} +{synopt:{opth note(string)}}Note to be added to data{p_end} +{synopt:{opth savep:ath(string)}}Directory path for saving files{p_end} +{synopt:{opth icp:base(string)}}Year for PPP conversions{p_end} +{synopt:{opt save13}}Requests data sets to be saved as Stata version 13{p_end} +{synopt:{opt restricted}}Specifies that data is restricted and will not be uploaded to Primus, and will be sent to special folder{p_end} +{synopt:{opt nopov:cal}}Will save data to pre-defined folder and will not be sent to PovCalNet{p_end} +{synopt:{opt replace}}Adds replace option to overwrite previous data with same name{p_end} +{synopt:{opt level(varname)}}Level variable of the PPP variable{p_end} +{synopt:{opt output(string)}}Path to save primus excel information{p_end} +{synopt:{opt welfare_primus(string)}}Primus specific welfare, if empty will take welfare variable{p_end} +{synopt:{opt ref:year(string)}}Specifies reference survey year. If left blank, the value from the year() option is used.{p_end} +{synopt:{opt auto:version}}Auto version control for data. If vermast() is not specified the same vintage as the one from previous version will be used. For new datapoints, both vermast() and veralt() will be equal to 1 {p_end} +{synopt:{opt overwrite}}Allows for replacement of existing vintages. The data is checked for consistency and only addition of new variables is allowed. {p_end} + +{dlgtab:Required} + + +{phang} +{opth countrycode(string)} specifies the three letter country code. See the Remarks section below for a {help upload##codes:list of WDI country codes}. + +{phang} +{opth year(string)} specifies the four digit year (YYYY) in which the survey interviews were conducted for this data file. +If this period spans two years (e.g. 2012-2013), specify the year with the greater number of months for the survey data collection, +or if the number of months are equal (e.g. 6 months in first year and 6 months in second year) specify the more recent year. +OR year of the first day of the interviews. + +{phang} +{opth welfaretype(string)} specifies the type of welfare measure for {cmd: welfare(varname)}. Accepted values are: {bf:INC} for income, {bf:CONS} for consumption, or {bf:EXP} for expenditure. + +{phang} +{opth welfare(varname)} specifies {it:varname} for the welfare variable (e.g. per capita consumption) in the data file. This variable should be in {bf:LCU at current prices}. + +{phang} +{opth weight(varname)} specifies {it:varname} for the survey weight in the data file. + +{phang} +{opth weighttype(string)} specifies the type of weight for {cmd: weight(varname)}. Accepted values are: {bf:FW} for frequency weights, or {bf:PW} for probability weights. + +{phang} +{opth hsize(string)} specifies {it:varname} for household size. + +{phang} +{opth hhid(varname)} specifies {it:varname} for the unique household identification number in the data file. + +{phang} +{opth ppp(varname)} specifies {it:varname} for the PPP conversion factor from the 2011 ICP for year 2011 in the data file; this must be a constant. + +{phang} +{opth cpi(varname)} specifies {it:varname} for the temporal price adjustment factor with respect to the ppp specified period. + +{phang} +{opth cpiperiod(string)} period that the CPI value covers. + +{phang} +{opth module(string)} Module that is being uploaded, if user specifies "ALL", or "GPWG" the data will be sent to the Primus approval process. + +{marker examples}{...} +{title:Examples} + +{phang}{cmd:. primus, countrycode(GEO) year(2015) welfare(gallT) welfaretype(CONS) welfshprosperity(gallT2) welfshprtype(CONS) weight(weight1) weighttype(FW) hsize(hhsize) hhid(hhid1) cpi(cpi2011) cpiperiod(year) ppp(icp2011) welfaredef(gallT) urban(urb) survey("`surveys'") vermast("`vermast_p'") harmonization(ECAPOV) veralt("`veralt_p'") othervariables(quarter gallT2) icpbase(2011) save13 savepath(\\wbntst01.worldbank.org\TeamDisk\GPWG\datalib\all_region) module(GPWG) output(\\Ecafile\eca-special\ECA_Databank\ECAPOVII\On_demand\GPWG\test.xlsx)} {p_end} + +{marker remarks}{...} +{title:Remarks} + +{marker codes}{...} +{pstd} +WDI three letter country codes: + +{space 6}{bf:Country}{col 41}{bf:Code} +{space 6}{hline 38} +{space 6}Afghanistan{col 41}AFG +{space 6}Albania {col 41}ALB +{space 6}Algeria {col 41}DZA +{space 6}American Samoa {col 41}ASM +{space 6}Andorra {col 41}ADO +{space 6}Angola {col 41}AGO +{space 6}Antigua and Barbuda {col 41}ATG +{space 6}Argentina {col 41}ARG +{space 6}Armenia {col 41}ARM +{space 6}Aruba {col 41}ABW +{space 6}Australia {col 41}AUS +{space 6}Austria {col 41}AUT +{space 6}Azerbaijan {col 41}AZE +{space 6}Bahamas, The {col 41}BHS +{space 6}Bahrain {col 41}BHR +{space 6}Bangladesh {col 41}BGD +{space 6}Barbados {col 41}BRB +{space 6}Belarus {col 41}BLR +{space 6}Belgium {col 41}BEL +{space 6}Belize {col 41}BLZ +{space 6}Benin {col 41}BEN +{space 6}Bermuda {col 41}BMU +{space 6}Bhutan {col 41}BTN +{space 6}Bolivia {col 41}BOL +{space 6}Bosnia and Herzegovina {col 41}BIH +{space 6}Botswana {col 41}BWA +{space 6}Brazil {col 41}BRA +{space 6}Brunei Darussalam {col 41}BRN +{space 6}Bulgaria {col 41}BGR +{space 6}Burkina Faso {col 41}BFA +{space 6}Burundi {col 41}BDI +{space 6}Cambodia {col 41}KHM +{space 6}Cameroon {col 41}CMR +{space 6}Canada {col 41}CAN +{space 6}Cape Verde {col 41}CPV +{space 6}Cayman Islands {col 41}CYM +{space 6}Central African Republic {col 41}CAF +{space 6}Chad {col 41}TCD +{space 6}Channel Islands {col 41}CHI +{space 6}Chile {col 41}CHL +{space 6}China {col 41}CHN +{space 6}Colombia {col 41}COL +{space 6}Comoros {col 41}COM +{space 6}Congo, Dem. Rep. {col 41}ZAR +{space 6}Congo, Rep. {col 41}COG +{space 6}Costa Rica {col 41}CRI +{space 6}Côte d'Ivoire {col 41}CIV +{space 6}Croatia {col 41}HRV +{space 6}Cuba {col 41}CUB +{space 6}Curaçao {col 41}CUW +{space 6}Cyprus {col 41}CYP +{space 6}Czech Republic {col 41}CZE +{space 6}Denmark {col 41}DNK +{space 6}Djibouti {col 41}DJI +{space 6}Dominica {col 41}DMA +{space 6}Dominican Republic {col 41}DOM +{space 6}Ecuador {col 41}ECU +{space 6}Egypt, Arab Rep. {col 41}EGY +{space 6}El Salvador {col 41}SLV +{space 6}Equatorial Guinea {col 41}GNQ +{space 6}Eritrea {col 41}ERI +{space 6}Estonia {col 41}EST +{space 6}Ethiopia {col 41}ETH +{space 6}Faeroe Islands {col 41}FRO +{space 6}Fiji {col 41}FJI +{space 6}Finland {col 41}FIN +{space 6}France {col 41}FRA +{space 6}French Polynesia {col 41}PYF +{space 6}Gabon {col 41}GAB +{space 6}Gambia, The {col 41}GMB +{space 6}Georgia {col 41}GEO +{space 6}Germany {col 41}DEU +{space 6}Ghana {col 41}GHA +{space 6}Greece {col 41}GRC +{space 6}Greenland {col 41}GRL +{space 6}Grenada {col 41}GRD +{space 6}Guam {col 41}GUM +{space 6}Guatemala {col 41}GTM +{space 6}Guinea {col 41}GIN +{space 6}Guinea-Bissau {col 41}GNB +{space 6}Guyana {col 41}GUY +{space 6}Haiti {col 41}HTI +{space 6}Honduras {col 41}HND +{space 6}Hong Kong SAR, China {col 41}HKG +{space 6}Hungary {col 41}HUN +{space 6}Iceland {col 41}ISL +{space 6}India {col 41}IND +{space 6}Indonesia {col 41}IDN +{space 6}Iran, Islamic Rep. {col 41}IRN +{space 6}Iraq {col 41}IRQ +{space 6}Ireland {col 41}IRL +{space 6}Isle of Man {col 41}IMY +{space 6}Israel {col 41}ISR +{space 6}Italy {col 41}ITA +{space 6}Jamaica {col 41}JAM +{space 6}Japan {col 41}JPN +{space 6}Jordan {col 41}JOR +{space 6}Kazakhstan {col 41}KAZ +{space 6}Kenya {col 41}KEN +{space 6}Kiribati {col 41}KIR +{space 6}Korea, Dem. Rep. {col 41}PRK +{space 6}Korea, Rep. {col 41}KOR +{space 6}Kosovo {col 41}KSV +{space 6}Kuwait {col 41}KWT +{space 6}Kyrgyz Republic {col 41}KGZ +{space 6}Lao PDR {col 41}LAO +{space 6}Latvia {col 41}LVA +{space 6}Lebanon {col 41}LBN +{space 6}Lesotho {col 41}LSO +{space 6}Liberia {col 41}LBR +{space 6}Libya {col 41}LBY +{space 6}Liechtenstein {col 41}LIE +{space 6}Lithuania {col 41}LTU +{space 6}Luxembourg {col 41}LUX +{space 6}Macao SAR, China {col 41}MAC +{space 6}Macedonia, FYR {col 41}MKD +{space 6}Madagascar {col 41}MDG +{space 6}Malawi {col 41}MWI +{space 6}Malaysia {col 41}MYS +{space 6}Maldives {col 41}MDV +{space 6}Mali {col 41}MLI +{space 6}Malta {col 41}MLT +{space 6}Marshall Islands {col 41}MHL +{space 6}Mauritania {col 41}MRT +{space 6}Mauritius {col 41}MUS +{space 6}Mexico {col 41}MEX +{space 6}Micronesia, Fed. Sts. {col 41}FSM +{space 6}Moldova {col 41}MDA +{space 6}Monaco {col 41}MCO +{space 6}Mongolia {col 41}MNG +{space 6}Montenegro {col 41}MNE +{space 6}Morocco {col 41}MAR +{space 6}Mozambique {col 41}MOZ +{space 6}Myanmar {col 41}MMR +{space 6}Namibia {col 41}NAM +{space 6}Nepal {col 41}NPL +{space 6}Netherlands {col 41}NLD +{space 6}New Caledonia {col 41}NCL +{space 6}New Zealand {col 41}NZL +{space 6}Nicaragua {col 41}NIC +{space 6}Niger {col 41}NER +{space 6}Nigeria {col 41}NGA +{space 6}Northern Mariana Islands {col 41}MNP +{space 6}Norway {col 41}NOR +{space 6}Oman {col 41}OMN +{space 6}Pakistan {col 41}PAK +{space 6}Palau {col 41}PLW +{space 6}Panama {col 41}PAN +{space 6}Papua New Guinea {col 41}PNG +{space 6}Paraguay {col 41}PRY +{space 6}Peru {col 41}PER +{space 6}Philippines {col 41}PHL +{space 6}Poland {col 41}POL +{space 6}Portugal {col 41}PRT +{space 6}Puerto Rico {col 41}PRI +{space 6}Qatar {col 41}QAT +{space 6}Romania {col 41}ROM +{space 6}Russian Federation {col 41}RUS +{space 6}Rwanda {col 41}RWA +{space 6}Samoa {col 41}WSM +{space 6}San Marino {col 41}SMR +{space 6}São Tomé and Principe {col 41}STP +{space 6}Saudi Arabia {col 41}SAU +{space 6}Senegal {col 41}SEN +{space 6}Serbia {col 41}SRB +{space 6}Seychelles {col 41}SYC +{space 6}Sierra Leone {col 41}SLE +{space 6}Singapore {col 41}SGP +{space 6}Sint Maarten (Dutch part) {col 41}SXM +{space 6}Slovak Republic {col 41}SVK +{space 6}Slovenia {col 41}SVN +{space 6}Solomon Islands {col 41}SLB +{space 6}Somalia {col 41}SOM +{space 6}South Africa {col 41}ZAF +{space 6}South Sudan {col 41}SSD +{space 6}Spain {col 41}ESP +{space 6}Sri Lanka {col 41}LKA +{space 6}St. Kitts and Nevis {col 41}KNA +{space 6}St. Lucia {col 41}LCA +{space 6}St. Martin (French part) {col 41}MAF +{space 6}St. Vincent and the Grenadines {col 41}VCT +{space 6}Sudan {col 41}SDN +{space 6}Suriname {col 41}SUR +{space 6}Swaziland {col 41}SWZ +{space 6}Sweden {col 41}SWE +{space 6}Switzerland {col 41}CHE +{space 6}Syrian Arab Republic {col 41}SYR +{space 6}Tajikistan {col 41}TJK +{space 6}Tanzania {col 41}TZA +{space 6}Thailand {col 41}THA +{space 6}Timor-Leste {col 41}TMP +{space 6}Togo {col 41}TGO +{space 6}Tonga {col 41}TON +{space 6}Trinidad and Tobago {col 41}TTO +{space 6}Tunisia {col 41}TUN +{space 6}Turkey {col 41}TUR +{space 6}Turkmenistan {col 41}TKM +{space 6}Turks and Caicos Islands {col 41}TCA +{space 6}Tuvalu {col 41}TUV +{space 6}Uganda {col 41}UGA +{space 6}Ukraine {col 41}UKR +{space 6}United Arab Emirates {col 41}ARE +{space 6}United Kingdom {col 41}GBR +{space 6}United States {col 41}USA +{space 6}Uruguay {col 41}URY +{space 6}Uzbekistan {col 41}UZB +{space 6}Vanuatu {col 41}VUT +{space 6}Venezuela, RB {col 41}VEN +{space 6}Vietnam {col 41}VNM +{space 6}Virgin Islands (U.S.) {col 41}VIR +{space 6}West Bank and Gaza {col 41}WBG +{space 6}Yemen, Rep. {col 41}YEM +{space 6}Zambia {col 41}ZMB +{space 6}Zimbabwe {col 41}ZWE + + + diff --git a/p/primus_vintage.ado b/primus_vintage.ado similarity index 96% rename from p/primus_vintage.ado rename to primus_vintage.ado index c7b9d0f..242a235 100644 --- a/p/primus_vintage.ado +++ b/primus_vintage.ado @@ -1,149 +1,149 @@ -*! primus_vintage 0.2 April 2018 -*! Joao Pedro Azevedo, Raul A. Castaneda, Paul Corral, Jose Montes, Minh Nguyen - Global SWAT -* Modified for name checks, and improved info recollection - -cap program drop primus_vintage -program define primus_vintage, rclass - - version 11.0 - - syntax, country(string) [wrk all module(string) svy(string) /// - year(numlist int max=1 >1900) max SVYname] - -qui{ - tempfile _cattmp - - local opt - if ("`wrk'"!="") local opt wrkvintage - if ("`all'"!="") local opt allvintages - - foreach x in module country svy{ - if ("``x''"!="") local `x' =trim(upper("``x''")) - } - - - - //Local which returns all country surveys - if ("`svyname'"!=""){ - dlw_catalog, savepath("`_cattmp'") full code(`country') - if (_N!=0) levelsof acronym, local(thesurveys) clean - else local thesurveys = "" - return local thesurveys `thesurveys' - exit - } - else{ - //Bring in the Catalog - dlw_catalog, savepath("`_cattmp'") server(GMD) `opt' - if ("`year'"!="") keep if code=="`country'" & year==`year' & trim(upper(col))=="GMD" - else keep if code=="`country'" & trim(upper(col))=="GMD" - if ("`svy'"!="") keep if survname=="`svy'" - //Is year new? - return local newy=(_N==0) - - if (_N!=0){ - replace surveyid = trim(upper(surveyid)) - split surveyid, parse(_) - drop surveyid1 surveyid2 surveyid3 surveyid5 surveyid7 surveyid8 - replace surveyid6=subinstr(surveyid6,"V", "",.) - replace surveyid4=subinstr(surveyid4,"V", "",.) - - rename surveyid6 vera - rename surveyid4 verm - gen newa1 = real(vera)+1 - gen newm1 = real(verm) - gen newa = "0"+string(newa1) if length(string(newa1))==1 - - //Latest GPWG - levelsof verm if mod=="GPWG" & vera!="WRK", local(verm) clean - levelsof vera if mod=="GPWG" & vera!="WRK", local(vera) clean - if ("`vera'"!="") return local gpwg_a = "`vera'" - else return local gpwg_a = "" - - if ("`verm'"!="") return local gpwg_m= "`verm'" - else return local gpwg_m= "" - - //Latest working - levelsof verm if vera=="WRK", local(verm) clean - if ("`verm'"!="") return local gpwg_wm= "`verm'" - else return local gpwg_wm= "" - - //Latest all - levelsof verm if mod=="ALL" & vera!="WRK", local(verm) clean - levelsof vera if mod=="ALL" & vera!="WRK", local(vera) clean - if ("`vera'"!="") return local all_a = "`vera'" - else return local all_a = "" - - if ("`verm'"!="") return local all_m= "`verm'" - else return local all_m= "" - - - if ("`max'"!=""){ - egen maxa=max(newa1), by(survname) - if ("`svy'"==""){ - count - if (r(N)!=0) levelsof newa if newa1==maxa, local(maxa) clean - else local maxa = "" - } - else{ - count - if (r(N)!=0) levelsof newa if newa1==maxa & trim(upper(survname))==trim(upper("`svy'")), local(maxa) clean - else local maxa = "" - } - - if ("`maxa'"!="") return local maxa = "`maxa'" - else return local maxa = "01" - - egen maxm=max(newm1), by(survname) - if ("`svy'"==""){ - count - if (r(N)!=0) levelsof verm if newm1==maxm, local(maxm) clean - else local maxm = "" - } - else{ - count - if (r(N)!=0) levelsof verm if newm1==maxm & trim(upper(survname))==trim(upper("`svy'")), local(maxm) clean - else local maxm="" - } - - if ("`maxm'"!="") return local maxm = "`maxm'" - else return local maxm = "01" - - } - - if ("`module'"!=""){ - drop if upper(trim(mod))!=upper(trim("`module'")) - count - local _b = r(N) - return local newy_`module'=(`_b'==0) - - if (`_b'!=0){ - levelsof verm, local(newm) clean - levelsof newa, local(newa) clean - - if ("`newa'"!="") return local newa = "`newa'" - else return local newa = "" - - if ("`newm'"!="") return local newm = "`newm'" - else return local newm = "" - } - else{ - return local newa = "01" - return local newm = "01" - } - } - } - else{ - return local all_m = "01" - return local all_a = "01" - return local gpwg_m = "01" - return local gpwg_a = "01" - return local gpwg_wm= "" - if ("`max'"!=""){ - return local maxm = "01" - return local maxa = "01" - } - } - } - -} //END OF QUIETLY -end +*! primus_vintage 0.2 April 2018 +*! Joao Pedro Azevedo, Raul A. Castaneda, Paul Corral, Jose Montes, Minh Nguyen - Global SWAT +* Modified for name checks, and improved info recollection + +cap program drop primus_vintage +program define primus_vintage, rclass + + version 11.0 + + syntax, country(string) [wrk all module(string) svy(string) /// + year(numlist int max=1 >1900) max SVYname] + +qui{ + tempfile _cattmp + + local opt + if ("`wrk'"!="") local opt wrkvintage + if ("`all'"!="") local opt allvintages + + foreach x in module country svy{ + if ("``x''"!="") local `x' =trim(upper("``x''")) + } + + + + //Local which returns all country surveys + if ("`svyname'"!=""){ + dlw_catalog, savepath("`_cattmp'") full code(`country') + if (_N!=0) levelsof acronym, local(thesurveys) clean + else local thesurveys = "" + return local thesurveys `thesurveys' + exit + } + else{ + //Bring in the Catalog + dlw_catalog, savepath("`_cattmp'") server(GMD) `opt' + if ("`year'"!="") keep if code=="`country'" & year==`year' & trim(upper(col))=="GMD" + else keep if code=="`country'" & trim(upper(col))=="GMD" + if ("`svy'"!="") keep if survname=="`svy'" + //Is year new? + return local newy=(_N==0) + + if (_N!=0){ + replace surveyid = trim(upper(surveyid)) + split surveyid, parse(_) + drop surveyid1 surveyid2 surveyid3 surveyid5 surveyid7 surveyid8 + replace surveyid6=subinstr(surveyid6,"V", "",.) + replace surveyid4=subinstr(surveyid4,"V", "",.) + + rename surveyid6 vera + rename surveyid4 verm + gen newa1 = real(vera)+1 + gen newm1 = real(verm) + gen newa = "0"+string(newa1) if length(string(newa1))==1 + + //Latest GPWG + levelsof verm if mod=="GPWG" & vera!="WRK", local(verm) clean + levelsof vera if mod=="GPWG" & vera!="WRK", local(vera) clean + if ("`vera'"!="") return local gpwg_a = "`vera'" + else return local gpwg_a = "" + + if ("`verm'"!="") return local gpwg_m= "`verm'" + else return local gpwg_m= "" + + //Latest working + levelsof verm if vera=="WRK", local(verm) clean + if ("`verm'"!="") return local gpwg_wm= "`verm'" + else return local gpwg_wm= "" + + //Latest all + levelsof verm if mod=="ALL" & vera!="WRK", local(verm) clean + levelsof vera if mod=="ALL" & vera!="WRK", local(vera) clean + if ("`vera'"!="") return local all_a = "`vera'" + else return local all_a = "" + + if ("`verm'"!="") return local all_m= "`verm'" + else return local all_m= "" + + + if ("`max'"!=""){ + egen maxa=max(newa1), by(survname) + if ("`svy'"==""){ + count + if (r(N)!=0) levelsof newa if newa1==maxa, local(maxa) clean + else local maxa = "" + } + else{ + count + if (r(N)!=0) levelsof newa if newa1==maxa & trim(upper(survname))==trim(upper("`svy'")), local(maxa) clean + else local maxa = "" + } + + if ("`maxa'"!="") return local maxa = "`maxa'" + else return local maxa = "01" + + egen maxm=max(newm1), by(survname) + if ("`svy'"==""){ + count + if (r(N)!=0) levelsof verm if newm1==maxm, local(maxm) clean + else local maxm = "" + } + else{ + count + if (r(N)!=0) levelsof verm if newm1==maxm & trim(upper(survname))==trim(upper("`svy'")), local(maxm) clean + else local maxm="" + } + + if ("`maxm'"!="") return local maxm = "`maxm'" + else return local maxm = "01" + + } + + if ("`module'"!=""){ + drop if upper(trim(mod))!=upper(trim("`module'")) + count + local _b = r(N) + return local newy_`module'=(`_b'==0) + + if (`_b'!=0){ + levelsof verm, local(newm) clean + levelsof newa, local(newa) clean + + if ("`newa'"!="") return local newa = "`newa'" + else return local newa = "" + + if ("`newm'"!="") return local newm = "`newm'" + else return local newm = "" + } + else{ + return local newa = "01" + return local newm = "01" + } + } + } + else{ + return local all_m = "01" + return local all_a = "01" + return local gpwg_m = "01" + return local gpwg_a = "01" + return local gpwg_wm= "" + if ("`max'"!=""){ + return local maxm = "01" + return local maxa = "01" + } + } + } + +} //END OF QUIETLY +end diff --git a/stata.toc b/stata.toc new file mode 100644 index 0000000..8d40c08 --- /dev/null +++ b/stata.toc @@ -0,0 +1,9 @@ +v 0.0.0.9000 +d Materials by R.Andres Castaneda +d The World Bank +d acastanedaa@worldbank.org +d https://github.com/worldbank/primus + +d 'primus': The Primus ado files for Stata in this GitHub repo are a critical component of this process. These allow for data sharing and file upload service that ensures that estimations are based on identical source data. + +p primus