Skip to content

Commit

Permalink
Merge pull request #25 from PovcalNet-Team/compare_update
Browse files Browse the repository at this point in the history
pcn compare update to wor with vinatges
  • Loading branch information
randrescastaneda authored Sep 10, 2020
2 parents 473b5ed + 059cf7e commit 790a1b1
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 19 deletions.
74 changes: 65 additions & 9 deletions pcn_compare.ado
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ syntax [anything(name=subcmd id="subcommand")], ///
IDvar(string) ///
MAINv(string) ///
server(string) ///
server0(string) ///
DISvar(string) ///
check(string) ///
POVline(string) ///
Expand All @@ -33,6 +34,8 @@ year(string) ///
FILLgaps ///
AGGregate ///
wb ///
vintage(string) ///
vintage0(string) ///
]

version 14
Expand All @@ -54,7 +57,7 @@ qui {
// relevant macros
if ("`idvar'" == "" & "`aggregate'" != "") loc idvar "year povertyline "
else if ("`idvar'" == "" & "`wb'" != "") loc idvar "regioncode year povertyline"
else if ("`idvar'" == "") loc idvar "regioncode countrycode year povertyline coveragetype datatype"
else if ("`idvar'" == "") loc idvar "countrycode year povertyline coveragetype datatype"
else loc idvar = lower("`idvar'")

if ("`mainv'" == "") loc mainv "headcount"
Expand All @@ -69,7 +72,9 @@ qui {
if ("`disvar'" == "") loc disvar "main"
else loc disvar = lower("`disvar'")

if ("`sdlevel'" == "") loc sdlevel = 2
if ("`sdlevel'" == "") loc sdlevel = 2

if ("`server0'" != "") loc serverm = "server(`server0')"

if !inlist("`check'","main","all") {
noi di as err "Check varibables must be set to: main or all"
Expand All @@ -88,9 +93,32 @@ qui {
==================================================*/

// get testing data
povcalnet `wb', server(`server') povline(`povline') ///
if ("`vintage'" == ""){
povcalnet `wb', server(`server') povline(`povline') ///
country(`country') region(`region') ///
year(`year') `fillgaps' `aggregate' clear
}
else{
pcn_production load, server(`server') vintage(`vintage') clear
cap rename wbcode countrycode
if (!_rc){
cap gen povertyline = 1.9
cap replace surveyyear = round(surveyyear)
cap rename surveyyear
cap gen datatype = .
cap gen coveragetype = .
cap replace datatype = 1 if inlist(inc_con, "c", "C")
cap replace datatype = 2 if inlist(inc_con, "i", "I")
cap replace coveragetype = 2 if regexm(country, "(Urban)") & national == 0
cap replace coveragetype = 1 if regexm(country, "(Rural)") & national == 0
cap replace coveragetype = 3 if national == 1
cap replace countrycode = substr(countrycode,1,3)
replace headcount = headcount/100
replace gini = gini/100
}
}

replace povertyline=round(povertyline,.1) // some odd cases they do not quite match

cap isid `idvar'
if _rc {
Expand All @@ -114,22 +142,50 @@ qui {
replace `mv' = round(`mv', `tl')
}

cap replace coveragetype = 3 if coveragetype == 4 // One national

tempfile serverd
save `serverd'

// Get current data
povcalnet `wb', povline(`povline') ///
country(`country') region(`region') ///
year(`year') `fillgaps' `aggregate' clear

if ("`check'" == "main"){
keep `idvar' `mainv'
if ("`vintage0'" == ""){
povcalnet `wb', povline(`povline') ///
country(`country') region(`region') ///
year(`year') `serverm' `fillgaps' `aggregate' clear

if ("`check'" == "main"){
keep `idvar' `mainv'
}
}
else{
pcn_production load, `serverm' vintage(`vintage0') clear
cap rename wbcode countrycode
if (!_rc){
cap gen povertyline = 1.9
cap replace surveyyear = round(surveyyear)
cap rename surveyyear
cap gen datatype = .
cap gen coveragetype = .
cap replace datatype = 1 if inlist(inc_con, "c", "C")
cap replace datatype = 2 if inlist(inc_con, "i", "I")
cap replace coveragetype = 2 if regexm(country, "(Urban)") & national == 0
cap replace coveragetype = 1 if regexm(country, "(Rural)") & national == 0
cap replace coveragetype = 3 if national == 1
cap replace countrycode = substr(countrycode,1,3)
replace headcount = headcount/100
replace gini = gini/100
}
}

replace povertyline=round(povertyline,.1)


foreach mv of local mainv {
replace `mv' = round(`mv', `tl')
}

cap replace coveragetype = 3 if coveragetype == 4 // One national

tempfile PCN
save `PCN'

Expand Down
26 changes: 16 additions & 10 deletions pcn_create.ado
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,19 @@ qui {

cap isynth distribution, count(`country') year(`year') addvar(`addvar') server(AR) natppp /*
*/ `pause' `clear' `options'

// condition for synth
replace welfare = welfare*(365/12) //to monthly
if ("`country'"== "CHN"){
if ("`iscover'" == "R") keep if coverage == "Rural"
if ("`iscover'" == "U") keep if coverage == "Urban"
}

if (_rc) {

local status "error. loading"
local dlwnote "isynth distribution, count(`country') year(`year') addvar(`addvar') `pause' `clear' `options'"
}
else{
// condition for synth
replace welfare = welfare*(365/12) //to monthly
if ("`country'"== "CHN"){
if ("`iscover'" == "R") keep if coverage == "Rural"
if ("`iscover'" == "U") keep if coverage == "Urban"
}

gen urban = inlist(coveragetype, "urban", "Urban")
}
}
Expand Down Expand Up @@ -460,8 +459,15 @@ qui {
local cfiles "`rfile' `ufile' `wfile'"
} // end of special cases
else {
keep weight welfare
local urban ""
cap confirm variable urban
if (_rc){
keep weight welfare
local urban ""
}
else{
keep weight welfare urban
local urban "urban"
}
tempfile wfile
char _dta[cov] ""
if ("`module'" == "isynth") char _dta[cov] "`iscover'"
Expand Down

0 comments on commit 790a1b1

Please sign in to comment.