Skip to content

Commit

Permalink
Merge pull request #354 from worldbank/develop
Browse files Browse the repository at this point in the history
Merging develop to V7.3
  • Loading branch information
ankritisingh authored Nov 30, 2023
2 parents c161a8f + 7e71e8a commit aa5d320
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 99 deletions.
28 changes: 28 additions & 0 deletions run/iesave/iesave1.do
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,34 @@
version(`stata_ver')
assert _rc == 459

/*********************
Mutliple IDvars with missing values
*********************/

* Load auto
sysuse auto, clear

* Create ids that are only unique in combination
gen village = foreign
sort village make
by village : gen village_hhid = _n

* First test that it works without missing
iesave "`version_folder'/id_3.dta", ///
idvars(village village_hhid) version(15) replace

*Add this file to list of expected files
local expected_files `"`expected_files' "id_3.dta""'

* Create some missing vars
replace village = . in 5
replace village_hhid = . in 65

* Run iesave and test for expected error
cap iesave "~/delete-out/err_id_3.dta", ///
idvars(village village_hhid) version(15) replace
assert _rc == 459

/*********************
absence of userinfo
*********************/
Expand Down
12 changes: 11 additions & 1 deletion run/iesave/iesave2.do
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,15 @@

* Report with csv without path
iesave "`out'/auto-csv.dta", id(make) version(17.0) report(csv) replace


// Two ID vars -----------------------------------------------------------------

iesave "`out'/auto-2id.dta", id(make foreign) version(17.0) report replace

replace foreign = . in 1

cap iesave "`out'/auto-2id.dta", id(make foreign) version(17.0) report replace
assert _rc == 459


************************************************************************ The end.
37 changes: 37 additions & 0 deletions run/iesave/outputs/iesave2/auto-2id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
This report was created by the Stata command iesave (version 7.2). Read more about this command and the purpose of this report on https://dimewiki.worldbank.org/iesave

- **Number of observations:** 74
- **Number of variables:** 12
- **ID variable(s):** make foreign
- **.dta version used:** 14
- **Data signature:** 74:12(71728):2155345365:1865188037
- **Last saved by:** User info withheld, see option userinfo in command iesave.
- **Last saved at:** 17:01:39 28 Oct 2023

## Variable type: String

| Name | Label | Type | Complete obs | Number of levels |
|---|---|---|---|---|
| make | "Make and model" | str17 | 74 | 74 |

## Variable type: Continuous

| Name | Label | Type | Complete obs | Mean | Std Dev | p0 | p25 | p50 | p75 | p100 |
|---|---|---|---|---|---|---|---|---|---|---|
| displacement | "Displacement (cu. in.)" | int | 74 | 197.3 | 91.84 | 79 | 119 | 196 | 250 | 425 |
| gear_ratio | "Gear ratio" | float | 74 | 3.015 | .4563 | 2.19 | 2.73 | 2.955 | 3.37 | 3.89 |
| headroom | "Headroom (in.)" | float | 74 | 2.993 | .846 | 1.5 | 2.5 | 3 | 3.5 | 5 |
| length | "Length (in.)" | int | 74 | 187.9 | 22.27 | 142 | 170 | 192.5 | 204 | 233 |
| mpg | "Mileage (mpg)" | byte | 74 | 21.3 | 5.786 | 12 | 18 | 20 | 25 | 41 |
| price | "Price" | int | 74 | 6165 | 2949 | 3291 | 4195 | 5007 | 6342 | 15906 |
| rep78 | "Repair record 1978" | byte | 69 | 3.406 | .9899 | 1 | 3 | 3 | 4 | 5 |
| trunk | "Trunk space (cu. ft.)" | byte | 74 | 13.76 | 4.277 | 5 | 10 | 14 | 17 | 23 |
| turn | "Turn circle (ft.)" | byte | 74 | 39.65 | 4.399 | 31 | 36 | 40 | 43 | 51 |
| weight | "Weight (lbs.)" | int | 74 | 3019 | 777.2 | 1760 | 2240 | 3190 | 3600 | 4840 |

## Variable type: Categorical

| Name | Label | Value label | Complete obs | Number of levels | Number of unlabeled levels | Top count |
|---|---|---|---|---|---|---|
| foreign | "Car origin" | origin | 74 | 2 | 0 | Domestic:52 Foreign:22 |

2 changes: 1 addition & 1 deletion run/iesave/outputs/iesave2/auto-csv.csv
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ID variable(s):,make
.dta version used:,14
Data signature:,74:12(71728):2155345365:1865188037
Last saved by:,User info withheld, see option userinfo in command iesave.
Last saved at:,12:07:04 11 Apr 2023
Last saved at:,17:01:38 28 Oct 2023

Variable type: String
Name,Label,Type,Complete obs,Number of levels
Expand Down
4 changes: 2 additions & 2 deletions run/iesave/outputs/iesave2/auto-noalpha.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ This report was created by the Stata command iesave (version 7.2). Read more abo
- **ID variable(s):** make
- **.dta version used:** 14
- **Data signature:** 74:12(71728):2155345365:1865188037
- **Last saved by:** wb462869 - PCD85M04J3
- **Last saved at:** 12:07:04 11 Apr 2023
- **Last saved by:** luizaandrade - BFI-33299
- **Last saved at:** 17:01:38 28 Oct 2023

## Variable type: String

Expand Down
4 changes: 2 additions & 2 deletions run/iesave/outputs/iesave2/auto-userinfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ This report was created by the Stata command iesave (version 7.2). Read more abo
- **ID variable(s):** make
- **.dta version used:** 14
- **Data signature:** 74:12(71728):2155345365:1865188037
- **Last saved by:** wb462869 - PCD85M04J3
- **Last saved at:** 12:07:03 11 Apr 2023
- **Last saved by:** luizaandrade - BFI-33299
- **Last saved at:** 17:01:38 28 Oct 2023

## Variable type: String

Expand Down
2 changes: 1 addition & 1 deletion run/iesave/outputs/iesave2/auto.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This report was created by the Stata command iesave (version 7.2). Read more abo
- **.dta version used:** 14
- **Data signature:** 74:12(71728):2155345365:1865188037
- **Last saved by:** User info withheld, see option userinfo in command iesave.
- **Last saved at:** 12:07:03 11 Apr 2023
- **Last saved at:** 17:01:38 28 Oct 2023

## Variable type: String

Expand Down
4 changes: 2 additions & 2 deletions run/iesave/outputs/iesave2/my-path.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Number of variables:,12
ID variable(s):,make
.dta version used:,14
Data signature:,74:12(71728):2155345365:1865188037
Last saved by:,wb462869 - PCD85M04J3
Last saved at:,12:07:04 11 Apr 2023
Last saved by:,luizaandrade - BFI-33299
Last saved at:,17:01:38 28 Oct 2023

Variable type: String
Name,Label,Type,Complete obs,Number of levels
Expand Down
4 changes: 2 additions & 2 deletions run/iesave/outputs/iesave2/my-path.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ This report was created by the Stata command iesave (version 7.2). Read more abo
- **ID variable(s):** make
- **.dta version used:** 14
- **Data signature:** 74:12(71728):2155345365:1865188037
- **Last saved by:** wb462869 - PCD85M04J3
- **Last saved at:** 12:07:04 11 Apr 2023
- **Last saved by:** luizaandrade - BFI-33299
- **Last saved at:** 17:01:38 28 Oct 2023

## Variable type: String

Expand Down
4 changes: 2 additions & 2 deletions src/ado_files/ieboilstart.ado
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
else {
local aopterr `"You provided the sub-option [`aoption']."'
}
noi di as error `"{phang}The option [`adopath'] requires one of the sub-options [strict] or [nostrict]. `aopterr' See help file for more details.{p_end}"'
noi di as error `"{phang}The option {inp:adopath(}{it:{res:`apath'}}{inp:)} requires one of the sub-options [strict] or [nostrict]. `aopterr' See help file for more details.{p_end}"'
error 198
}
Expand Down Expand Up @@ -310,7 +310,7 @@
}
noi di ""
noi di as result "{phang}{err:IMPORTANT:} One important setting of this command – the Stata version – cannot be set inside the command due to how this setting works. The setting has been prepared by this command, and you only need to write \`r(version)' after this command (include the apostrophes) for the version setting to be applied.{p_end}"
noi di as result "{phang}{err:IMPORTANT:} One setting of this command requires that \`r(version)' is run on the immediate line after this command. Include the quotes \` and ' in \`r(version)'. This sets the Stata version which cannot be done for this purpose inside the command. This message will show regardless if this is already done. Read more on this requirement in the {help ieboilstart :help file}.{p_end}"
}
}
Expand Down
101 changes: 42 additions & 59 deletions src/ado_files/iegraph.ado
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ cap program drop iegraph
confbarsnone(varlist) ///
confintval(numlist min=1 max=1 >0 <1) ///
BARLabel ///
MLABColor(string) ///
BARColors(string) ///
MLABColor(string) ///
MLABPosition(numlist) ///
MLABSize(string) ///
BAROPTions(string) ///
Expand Down Expand Up @@ -163,8 +164,7 @@ cap program drop iegraph
}
if `LABEL_COL' {
if !inlist("`mlabcolor'", "background", "bg", "foreground", "fg") {
noi colorname `mlabcolor'
local LABEL_COL = r(LABEL_COL)
noi test_color, color(`mlabcolor') option("mlabcolor")
}
}
}
Expand Down Expand Up @@ -412,13 +412,14 @@ cap program drop iegraph
*Create the bar for this group

if "`grayscale'" == "" {
colorPicker `tmtGroupCount' `graphCount'
colorPicker, gnum(`tmtGroupCount') tnum(`graphCount') ///
colors(`"`barcolors'"')
}
else {
grayPicker `tmtGroupCount' `graphCount'
}

local tmtGroupBars `"`tmtGroupBars' (bar mean position if position == `tmtGroupCount', `baroptions' color("`r(color)'") lcolor(black) ) "'
local tmtGroupBars `"`tmtGroupBars' (bar mean position if position == `tmtGroupCount', color("`r(color)'") lcolor(black) `baroptions' ) "'

************
*Create labels etc. for this group
Expand Down Expand Up @@ -604,43 +605,36 @@ end
******* on the number of vars *******
*******************************************
*******************************************
cap program drop colorPicker
program define colorPicker , rclass

args groupCount totalNumGroups

if `totalNumGroups' == 2 {

if `groupCount' == 1 return local color "215 25 28"
if `groupCount' == 2 return local color "43 123 182"
}
else if `totalNumGroups' == 3 {

if `groupCount' == 1 return local color "215 25 28"
if `groupCount' == 2 return local color "255 255 191"
if `groupCount' == 3 return local color "43 123 182"
}
else if `totalNumGroups' == 4 {

if `groupCount' == 1 return local color "215 25 28"
if `groupCount' == 2 return local color "255 255 191"
if `groupCount' == 3 return local color "171 217 233"
if `groupCount' == 4 return local color "43 123 182"
}
else {
cap program drop colorPicker
program define colorPicker , rclass

* gnum - number of this group
* tnum - total number of groups
* customc - custom list of colors
syntax, gnum(numlist >0) [tnum(numlist >0) colors(string)]

* Define default colors if no colors are provided
if missing("`colors'") {
if (`tnum' == 2) local colors `" "215 25 28" "43 123 182" "'
else if (`tnum' == 3) local colors `" "215 25 28" "255 255 191" "43 123 182" "'
else if (`tnum' == 4) local colors `" "215 25 28" "255 255 191" "171 217 233" "43 123 182" "'
else local colors `" "215 25 28" "253 174 93" "255 255 191" "171 217 233" "43 123 182" "'
}

*For five or more colors we repeat the same pattern
* Count number of colors
local color_count : word count `colors'

local colorNum = mod(`groupCount', 5)
if `colorNum' == 1 return local color "215 25 28"
if `colorNum' == 2 return local color "253 174 93"
if `colorNum' == 3 return local color "255 255 191"
if `colorNum' == 4 return local color "171 217 233"
if `colorNum' == 0 return local color "43 123 182"
* Modular devision of group numb with total number.
* This repeats colors if group num is higher than total number of colors
local color_num = mod(`gnum', `color_count')
if (`color_num' == 0) local color_num = `color_count'

}
* Pick, test and return color in list
local color : word `color_num' of `colors'
test_color , color("`color'") option("barcolors")
return local color "`color'"

end
end

*******************************************
*******************************************
Expand All @@ -654,19 +648,10 @@ end

args groupCount totalNumGroups

if `groupCount' == 1 {

return local color "black"
}

else if `groupCount' == 2 & `totalNumGroups' <= 3 {

return local color "gs14"
}
if (`groupCount' == 1) return local color "black"
else if (`groupCount'==2) & (`totalNumGroups'<=3) return local color "gs14"
else {

local grayscale = round( (`groupCount'-1) * (100 / (`totalNumGroups'-1) ))

local grayscale = round((`groupCount'-1)*(100/(`totalNumGroups'-1)))
return local color "`grayscale' `grayscale' `grayscale' `grayscale'"
}

Expand Down Expand Up @@ -799,19 +784,17 @@ end
end
cap prog drop colorname
prog def colorname, rclass
args name
cap prog drop test_color
prog def test_color, rclass
capture findfile color-`name'.style
syntax, color(string) option(string)
capture findfile color-`color'.style
if ( _rc == 601 ) {
noi di "{phang} WARNING: Option mlabcolor() was incorrectly specified. Only named colors in {help colorstyle} are accepted. Default color used.{p_end}"
return local LABEL_COL 0
noi di as error "{pstd} The color {inp:`color'} used in option {inp:`option'()} was incorrectly specified. Only colors listed in {help colorstyle} are accepted.{p_end}"
error 99
exit
}
end
Expand Down
18 changes: 10 additions & 8 deletions src/ado_files/iesave.ado
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,16 @@ qui {
capture isid `idvars'
if _rc {

*Test if there is missing values in the idvars
capture assert !missing(`idvars')
if _rc {
count if missing(`idvars')
noi di as error "{phang}The ID variable(s) `idvars' have missing values in `r(N)' observation(s). The ID variable(s) need to be fully identifying, meaning that missing values (., .a, .b ... .z) or the empty string are not allowed.{p_end}"
noi list `idvars' if missing(`idvars')
noi di ""
}
foreach idvar of local idvars {
*Test if there is missing values in the idvars
capture assert !missing(`idvar')
if _rc {
count if missing(`idvar')
noi di as error "{phang}The ID variable(s) `idvar' have missing values in `r(N)' observation(s). The ID variable(s) need to be fully identifying, meaning that missing values (., .a, .b ... .z) or the empty string are not allowed.{p_end}"
noi list `idvars' if missing(`idvar')
noi di ""
}
}

*Test if there are duplciates in the idvars
tempvar iedup
Expand Down
2 changes: 1 addition & 1 deletion src/ado_files/ietoolkit.ado
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ program ietoolkit, rclass
**********************/

* Stata versions commands in this package allows when applicable
return local stata_target_versions "12 12.0 12.1 13 13.0 13.1 14 14.0 14.1 14.2 15 15.0 15.1 16.0 16.1 17.0"
return local stata_target_versions "12 12.0 12.1 13 13.0 13.1 14 14.0 14.1 14.2 15 15.0 15.1 16.0 16.1 17.0 18.0"
return local dta_target_versions "12 13 14"

* Prepare returned locals
Expand Down
2 changes: 1 addition & 1 deletion src/help_files/iebaltab.sthlp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ will test for differences across the categories in {opt groupvar(varname)}.
{synopt :{opt rowv:arlabels}}Use the variable labels instead of variable name as row titles{p_end}
{synopt :{opt rowl:abels(nametitles)}}Manually set the row titles. See details on {it:nametitles} below{p_end}
{synopt :{opt nonote}}Suppress the default not at the bottom of the table{p_end}
{synopt :{opt addnotes(string)}}Add a manual note to the bottom of the table{p_end}
{synopt :{opt addnote(string)}}Add a manual note to the bottom of the table{p_end}

{marker exportoptions}{...}
{synopthdr:Export options}
Expand Down
Loading

0 comments on commit aa5d320

Please sign in to comment.