forked from eurostat/ACRO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
safe_graph.ado
73 lines (59 loc) · 3.04 KB
/
safe_graph.ado
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
* safe_graphs
* program to carry out disclosure risk on graphs
* Because graphs can't be assessed automtically, this progrma simply saves the image,
* uploads it the Excel output sheet and leaves a note for it to be 'reviewed'
* Copyright © European Commission. This software is released under the EUPL version 1.2.
* Acknowledgments: This code was developed as output of a project entitled "Access to European Microdata in Eurostat Safe Centre: Automatic checking of the output" (Specific Contract N° 000058 ESTAT N°2019.0337, under the Framework Contract 2018.0086) by Elizabeth Green, Felix Ritchie and Jim Smith of the University of the West of England, Bristol.
* For queries contact [email protected].
* Created September 2020 by Felix & Lizzie
* Additional options compared to standard command:
* outsheet(nn) specifies output sheet nn
* globals:
* SDC parameters (system manager set)
* ACRO_by_num used to index sheets if by values used
* ACRO_out_file Output_file name (set by user in safe_setup
* ACRO_temp_image Temp file to hold PNG graphic file
* returns:
* outcome coded outcome (always "review required")
* Note: graph is not 'byable' - by() is specified in options
capture program drop safe_graph
program define safe_graph , rclass
syntax anything [if] [in] [, *]
marksample touse , strok
* switch on and off - quietly in normal use, noisily for testing
quietly {
* noisily {
* stage 1: extract paramater values and settings
******************************************************************************
local stat = "`1'"
local sub_stat = "`2'"
if "` stat'" == "graph" {
local stat = "`2'"
local sub_stat = "`3'"
}
local full_type = "`stat'"
if "` stat'" == "twoway" {
local full_type = "`stat' `sub_stat'"
}
local cmd_type = "graph: `full_type'"
* get additional parameters specific to safe_estimates - remove this from the standard 'options' list
extract_parameter "output_sheet" `"`options'"'
local temp = r(extract)
local output_sheet = subinstr(`"`temp'"', `"""', "", .)
local clean_cmd = subinstr(`"`0'"', `"output_sheet(`temp')"', "", .)
* finally, where to place outputs in the Excel sheet - -how much space should be left for the summary and the clean tble:
local first_line = 5
* stage 2: run the command
******************************************************************************************************************************
safe_write_results `"`clean_cmd'"' $ACRO_outcome_f_review "$ACRO_out_file" "`output_sheet'" "no exception" no_print
`clean_cmd'
graph export "$ACRO_temp_image" , replace
putexcel set "$ACRO_out_file" , sheet("`output_sheet'") modify
putexcel A5 = picture("$ACRO_temp_image")
capture erase "$ACRO_temp_image"
return scalar outcome = $ACRO_outcome_f_review
return local desc = "`cmd_type'"
noisily safe_write_index `"`output_sheet'"' "`cmd_type'" $ACRO_outcome_f_review " "
}
* end quietly/noisily
end