Skip to content

Commit

Permalink
Merge pull request #22 from lsms-worldbank/dev
Browse files Browse the repository at this point in the history
Merge to main to test new GHA
  • Loading branch information
kbjarkefur authored Jan 18, 2024
2 parents 1c0d45b + a256c0c commit ba50df7
Show file tree
Hide file tree
Showing 34 changed files with 774 additions and 101 deletions.
11 changes: 6 additions & 5 deletions src/ado/labeller.ado
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cap program drop labeller
program define labeller, rclass

version 13.0
qui {
version 14

* UPDATE THESE LOCALS FOR EACH NEW VERSION PUBLISHED
local version "1.0"
Expand Down Expand Up @@ -37,9 +38,9 @@ cap program drop labeller
exit
}
* Run the subcommand
`subcommand', `parameters'
noi `subcommand', `parameters'
}

}
end

cap program drop output_verbose
Expand Down Expand Up @@ -68,7 +69,7 @@ end
cap program drop output_veryverbose
program define output_veryverbose

syntax, title(string) ttitle1(string) ttitle2(string) [vars(varlist)]
syntax, title(string) ttitle1(string) ttitle2(string) [varlist(varlist)]

noi di as text "{pstd}`title'{p_end}"

Expand All @@ -90,7 +91,7 @@ cap program drop output_veryverbose
noi di as text "{p2col `p2_all':{it:{ul:`ttitle1'}}} {it:{ul:`ttitle2'}}" _n

* Write each label
foreach varname of local vars {
foreach varname of local varlist {
local varlab : variable label `varname'
noi di as text "{p2col `p2_all':{bf:`varname'}} {text:`varlab'}" _n
}
Expand Down
2 changes: 1 addition & 1 deletion src/ado/lbl_assert_no_long_varlbl.ado
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cap program drop lbl_assert_no_long_varlbl

version 14

syntax [varlist], [MAXlen(integer 80)]
syntax, [MAXlen(integer 80) Varlist(varlist)]

qui {

Expand Down
16 changes: 11 additions & 5 deletions src/ado/lbl_assert_no_pipes.ado
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

cap program drop lbl_assert_no_pipes
program define lbl_assert_no_pipes
qui {
version 14

* Update the syntax. This is only a placeholder to make the command run
syntax, [IGnore_pipes(string) OUTput_level(string)]
syntax, [IGnore_pipes(string) OUTput_level(string) Varlist(varlist)]

* Get all variables in varlist or get all variables
ds `varlist'
local varlist "`r(varlist)'"

* Set defaults
if missing("`output_level'") local output_level "verbose"
Expand All @@ -14,7 +20,7 @@ cap program drop lbl_assert_no_pipes
}

* Get the list of pipes used and the vars they are used for
qui lbl_list_pipes, output_level(minimal)
qui lbl_list_pipes, output_level(minimal) varlist("`varlist'")
local pipes_found "`r(pipes)'"

* Add the vars with remaining pipes for each pipe
Expand All @@ -36,10 +42,10 @@ cap program drop lbl_assert_no_pipes
local title "{err:Pipe %`pipe'% still in variable(s):}"
if ("`output_level'" == "verbose") {
//noi di `"output_verbose, title("`title'") values("``pipe'_v'")"'
labeller output_verbose title("`title'") values("``pipe'_v'")
noi labeller output_verbose title("`title'") values("``pipe'_v'")
}
else if ("`output_level'" == "veryverbose") {
labeller output_veryverbose title("`title'") vars("``pipe'_v'") ///
noi labeller output_veryverbose title("`title'") varlist("``pipe'_v'") ///
ttitle1("Variable") ttitle2("Variable label")
noi di as text "{p2line}" _n
}
Expand All @@ -51,5 +57,5 @@ cap program drop lbl_assert_no_pipes
else {
noi di as result _n "{pstd}No more pipes in dataset{p_end}"
}

}
end
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
*! version XX XXXXXXXXX ADAUTHORNAME ADCONTACTINFO

cap program drop lbl_assert_var_have_lbl
program define lbl_assert_var_have_lbl, rclass
cap program drop lbl_assert_have_varlbl
program define lbl_assert_have_varlbl, rclass

version 13
version 14

syntax [varlist]
syntax , Varlist(varlist)

qui {

* Get all variables in varlist or get all variables
ds `varlist'
local varlist "`r(varlist)'"

* look for variables without a label
lbl_list_no_var_lbl `varlist'
lbl_list_no_varlbl, varlist(`varlist')
local any_wo_var_lbl = (`r(count_matches)' > 0)
local n_wo_var_lbl = "`r(count_matches)'"
local which_no_var_lbl "`r(varlist)'"
Expand All @@ -29,7 +33,6 @@ cap program drop lbl_assert_var_have_lbl
else {
di as result "{pstd}No variables found with a variable label.{p_end}"
}

}

end
6 changes: 3 additions & 3 deletions src/ado/lbl_list_long_varlbl.ado
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ cap program drop lbl_list_long_varlbl

version 14

syntax [varlist], [MAXlen(integer 80)]
syntax, [MAXlen(integer 80) Varlist(varlist)]

qui {

* get list of all variables
ds `varlist', has(varlabel)
local vars = r(varlist)
local varlist = r(varlist)

* initialize list of variables with labels that are too long
local vars_lbl_too_long ""

* populate list of variables
foreach var of local vars {
foreach var of local varlist {

* extract variable label
local var_lbl : variable label `var'
Expand Down
112 changes: 112 additions & 0 deletions src/ado/lbl_list_matching_vals.ado
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
*! version XX XXXXXXXXX ADAUTHORNAME ADCONTACTINFO

cap program drop lbl_list_matching_vals
program define lbl_list_matching_vals, rclass

version 14

syntax, pattern(string) [NEGate VERbose Varlist(varlist)]

qui {

* get list of variables with value labels
ds `varlist', has(vallabel)
local vars_w_val_lbl "`r(varlist)'"
local n_vars_w_val_lbl : list sizeof vars_w_val_lbl

* get list of labels for vars in varlist
* providing a varlist if none specified
if (mi("`varlist'")) {
d, varlist
local varlist = r(varlist)
}
local val_lbls_for_varlist ""
foreach var of local varlist {
local val_lbl_curr_var : value label `var'
local val_lbls_for_varlist "`val_lbls_for_varlist' `val_lbl_curr_var'"
}

* compile the list of labels with matching elements
* by working in a frame so that the data can be converted into
* a data set of labels
tempname val_lbls
frame copy default `val_lbls'
frame `val_lbls' {

* create a data set of labels
uselabel, clear var

* capture the list of value labels with a matching element
d // for computing observation count
if (`r(N)' == 0) {
local val_lbls_w_matching_val ""
}
else if (`r(N)' > 0) {

* labels that match in whole data set
levelsof lname if ustrregexm(label, "`pattern'"), ///
local(val_lbls_w_matching_val) clean

* construct list of matching variables
if (mi("`negate'")) {
local val_lbls_matching_in_varlist : list val_lbls_for_varlist & val_lbls_w_matching_val
}
if (!mi("`negate'")) {
* all label names
levelsof lname, local(all_val_lbls) clean
* labels to exclude
local val_lbls_to_exclude "`val_lbls_w_matching_val'"
local val_lbls_to_exclude : list val_lbls_to_exclude & val_lbls_for_varlist
* compliment of matching labels
local val_lbls_matching_in_varlist : list all_val_lbls - val_lbls_to_exclude
}

}

}

* compile list of variables whose value labels have a matching element
if (mi("`val_lbls_matching_in_varlist'")) {
local vars_w_matching_val_lbl ""
}
else if (!mi("`val_lbls_matching_in_varlist'")) {
* list variables with one of the variable label names piped into `has()'
ds, has(vallabel `val_lbls_matching_in_varlist')
local vars_w_matching_val_lbl "`r(varlist)'"
* restrict to variables in the varlist with labels
local vars_w_matching_val_lbl : list vars_w_matching_val_lbl & vars_w_val_lbl
}

* compile the list of matching labels
* capture this from the val_lbls frame so that present in main frame
local val_lbls_matching_in_varlist "`val_lbls_matching_in_varlist'"

* compute the number of matches
local n_matching_val_lbls : list sizeof val_lbls_matching_in_varlist
local n_matching_vars : list sizeof vars_w_matching_val_lbl

* report on findings
if (`n_matching_val_lbls' == 0) {
noi: di as result "No matching value labels found"
}
else if (`n_matching_val_lbls' > 0) {
* print basic results message
noi: di as result "Matching value labels found."
noi: di as result "`n_matching_val_lbls' value labels attached to `n_matching_vars' variables."
noi: di as result "Value labels: `val_lbls_matching_in_varlist'"
noi: di as result "Variables: `vars_w_matching_val_lbl'"
* if verbose mode, print out matching value label sets
if (!mi("`verbose'")) {
noi: label list `val_lbls_matching_in_varlist'
}
}

* return results
return local lbl_count "`n_matching_val_lbls'"
return local val_lbl_list "`val_lbls_matching_in_varlist'"
return local var_count "`n_matching_vars'"
return local varlist "`vars_w_matching_val_lbl'"

}

end
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
capture program drop lbl_list_matching_vars
program define lbl_list_matching_vars, rclass
program define lbl_list_matching_vars, rclass

qui {

syntax anything (name=pattern), [varlist(varlist)] [NEGate]
syntax anything (name=pattern), [varlist(varlist) NEGate]

version 14

* get list of all (matching) variables
ds `varlist', has(varlabel)
local vars = r(varlist)
local varlist = r(varlist)

local vars_w_match_lbl ""

foreach var of local vars {
foreach var of local varlist {

* extract the variable label
local var_label : variable label `var'
Expand All @@ -28,7 +28,6 @@ qui {
else if (!mi("`negate'") & (`lbl_matches' == 0)) {
local vars_w_match_lbl "`vars_w_match_lbl' `var'"
}

}

* compute the number of matches
Expand All @@ -46,8 +45,7 @@ qui {
else if (`n_matches' == 0) {
noi di as error "No matching variables found"
noi di as result "If this result is unexpected, please check the regular expression provided."
}

}
}

end
18 changes: 7 additions & 11 deletions src/ado/lbl_list_no_var_lbl.ado → src/ado/lbl_list_no_varlbl.ado
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
*! version XX XXXXXXXXX ADAUTHORNAME ADCONTACTINFO

cap program drop lbl_list_no_var_lbl
program define lbl_list_no_var_lbl, rclass
cap program drop lbl_list_no_varlbl
program define lbl_list_no_varlbl, rclass

version 13
version 14

syntax [varlist]
syntax, [Varlist(varlist)]

qui {

* get all variables that lack a variable label
ds `varlist', not(varlabel)
local vars "`r(varlist)'"

* reset varlist to avoid collision with varlist in syntax
local varlist ""
local varlist "`r(varlist)'"

* compute the number of matches
local n_matches : list sizeof vars
local n_matches : list sizeof varlist

* return the varlist and count of matches
return local varlist "`vars'"
return local varlist "`varlist'"
return local count_matches "`n_matches'"

* message about outcome
Expand All @@ -31,7 +28,6 @@ cap program drop lbl_list_no_var_lbl
else if (`n_matches' == 0) {
noi di as result "{pstd}No variables found without a label{p_end}"
}

}

end
18 changes: 13 additions & 5 deletions src/ado/lbl_list_pipes.ado
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
cap program drop lbl_list_pipes
program define lbl_list_pipes, rclass

qui {

version 14

* Update the syntax. This is only a placeholder to make the command run
syntax , [IGnore_pipes(string) OUTput_level(string)]
syntax, [IGnore_pipes(string) OUTput_level(string) Varlist(varlist)]

* Get all variables in varlist or get all variables
ds `varlist'
local varlist "`r(varlist)'"

* Set defaults
if missing("`output_level'") local output_level "verbose"
Expand All @@ -21,7 +29,7 @@ cap program drop lbl_list_pipes
**************************************************

* Loop over all variables to list all pipes and all vars each are used for
foreach var of varlist _all {
foreach var of local varlist {

* Reset locals used in serach
local is_pipe 0
Expand Down Expand Up @@ -94,10 +102,10 @@ cap program drop lbl_list_pipes

if ("`output_level'" == "verbose") {
//noi di `"output_verbose, title("`title'") values("``pipe'_v'")"'
labeller output_verbose title("`title'") values("``pipe'_v'")
noi labeller output_verbose title("`title'") values("``pipe'_v'")
}
else if ("`output_level'" == "veryverbose") {
labeller output_veryverbose title("`title'") vars("``pipe'_v'") ///
noi labeller output_veryverbose title("`title'") varlist("``pipe'_v'") ///
ttitle1("Variable") ttitle2("Variable label")
noi di as text "{p2line}" _n
}
Expand All @@ -116,5 +124,5 @@ cap program drop lbl_list_pipes

* Output the pipes found
return local pipes "`pipes_found'"

}
end
Loading

0 comments on commit ba50df7

Please sign in to comment.