ui-macos/bits/runpython.do: report which platforms we're compiling for.

Just as a quick reminder, in case you're building a fat binary and you don't
have all the architectures actually installed.

exec >&2
redo-ifchange runpython.c
ARCHES=""
printf "Platforms: "
for d in /usr/libexec/gcc/darwin/*; do
    PLAT=$(basename "$d")
    ARCHES="$ARCHES -arch $PLAT"
    printf "$PLAT "
done
printf "\n"
gcc $ARCHES \
	-Wall -o $3 runpython.c \
	-I/usr/include/python2.5 \
	-lpython2.5

exec >&2
redo-ifchange runpython.c
ARCHES=""
for d in /usr/libexec/gcc/darwin/*; do
    ARCHES="$ARCHES -arch $(basename $d)"
done
gcc $ARCHES \
	-Wall -o $3 runpython.c \
	-I/usr/include/python2.5 \
	-lpython2.5


Delete 101_PreliminaryAnalysis.do

Delete 101_PreliminaryAnalysis.do

/*-------------------------------------------------------------------------------
# Name:		101_PreliminaryAnalysis
# Purpose:	Create preliminary analysis Uganda
# Author:	Tim Essam, Ph.D.
# Created:	01/12/2015
# Owner:	USAID GeoCenter | OakStream Systems, LLC
# License:	MIT License
# Ado(s):	see below
#-------------------------------------------------------------------------------
*/
capture log close
clear
log using "$pathlog/prelimAnalysis", replace

* Load in shock module to look at different shocks faced by hh
use "$pathraw/GSEC16.dta", clear

* List the label for shocks and their cross-walk codes
label list df_SHOCK df_SHOCKRECOVERY

* Tabulate total shocks reported
tab h16q00 if h16q01 == 1

* Calculate total shocks per household
g byte anyshock = (h16q01 ==1)
egen totShock = total(anyshock), by(HHID)
la var anyshock "household reported at least one shock"
la var totShock "total shocks"

* Quickly get a sense of frequency of shocks at HH-level
bys HHID: gen id = _n
tab totShock if id==1, mi

la var totShock "Total shocks"

* Create shock buckets

/*ag 		= other crop damage; input price increase; death of livestock
* aglow		= unusually low prices for ag output
* conflit 	= theft/robbery/violence
* disaster 	= drought, flood, heavy rains, landslides, fire
* drought	= drought/irregular rains
* financial	= loss of non-farm job
* pricedown = price fall of food items
* health	= death of hh member; illness of hh member
* other 	= loss of house; displacement; other
* theft		= theft of money/assets/output/etc.. */
g byte ag 		= inlist(h16q00, 104, 105, 106) &  inlist(h16q01, 1) == 1
g byte aglow	= inlist(h16q00, 107) &  inlist(h16q01, 1) == 1
g byte conflict = inlist(h16q00, 116) &  inlist(h16q01, 1) == 1
g byte drought	= inlist(h16q00, 101) &  inlist(h16q01, 1) == 1
g byte disaster = inlist(h16q00, 102, 103, 117) &  inlist(h16q01, 1) == 1
g byte financial= inlist(h16q00, 108, 109) &  inlist(h16q01, 1) == 1
g byte health 	= inlist(h16q00, 110, 111, 112, 113) &  inlist(h16q01, 1) == 1
g byte other 	= inlist(h16q00, 118) &  inlist(h16q01, 1) == 1
g byte theft	= inlist(h16q00, 114, 115) &  inlist(h16q01, 1) == 1

la var ag "Agriculture"
la var aglow "Low ag output prices"
la var conflict "Conflict"
la var disaster "Disaster"
la var financial "Financial"
la var health "Health"
la var other "Other"
la var theft "Theft"
la var drought "lack of rainfall or drought"

* How did households cope?
label list df_SHOCKRECOVERY

/* Coping Mechanisms - What are good v. bad coping strategies? From (Heltberg et al., 2013)
	http://siteresources.worldbank.org/EXTNWDR2013/Resources/8258024-1352909193861/
	8936935-1356011448215/8986901-1380568255405/WDR15_bp_What_are_the_Sources_of_Risk_Oviedo.pdf
	Good Coping:: use of savings, credit, asset sales, additional employment,
					migration, and assistance
	Bad Coping : increases vulnerabiliy* compromising health and edudcation
				expenses, productive asset sales, conumsumption reductions
				*/

g byte goodcope = inlist(h16q4a, 1, 2, 4, 5, 6, 7, 8, 9, 10, 12) &  inlist(h16q01, 1) == 1
g byte badcope 	= inlist(h16q4a, 3, 13, 14, 15, 11) &  inlist(h16q01, 1) == 1
g byte incReduction = h16q3a == 1

la var goodcope "Good primary coping strategy"
la var badcope "Bad primary coping strategy"
la var incReduction "Income reduction due to shock"

* Collapse data to househld level and merge back with GIS info
ds (h16* result_code id ), not
keep `r(varlist)'

* Collapse everything down to HH-level using max values for all vars
* Copy variable labels to reapply after collapse
include "$pathdo/copylabels.do"

#delimit ;
	collapse (max) ag aglow conflict drought disaster financial health other theft
	goodcope badcope incReduction anyshock totShock, by(HHID) fast;
#delimit cr

* Reapply variable lables & value labels
include "$pathdo/attachlabels.do"


added distinct vals to varlabelbook

added distinct vals to varlabelbook

*! v0.1 Apoorva Lal
// returns dataset with dataset's <describe> output
// useful for very wide datasets / datasets with useless/uninformative
// variable names
// e.g. USAID's Demographic and Health Surveys

pr define varlabelbook
    syntax [anything]
    qui compress
    qui ds `anything'
    loc vl "`r(varlist)'"
    loc nrows: word count `vl'
    forv i = 1/`nrows' {
        loc vname_`i'    :word `i' of `vl'
        loc var_label_`i':var l `vname_`i''
        loc type_`i'     :type `vname_`i''
        if inlist("`type_`i''", "byte","int") {
            count_uniq `vname_`i''
            loc distinct_vals_`i' = `r(nv)'
            if `r(nv)' <= 20 {
                loc la_`vname_`i'': val l `vname_`i''
                loc label_exists = cond("`la_`vname_`i'''" != "",1,0)
                if `label_exists'{
                loc values_and_labels_`i' ""
                qui levelsof `vname_`i'', loc(`vname_`i''_l) clean
                    foreach val in ``vname_`i''_l' {
                        loc vlab: label `la_`vname_`i''' `val'
                        loc curr_value_label = subinstr("`vlab'",`"""',"",.)  // " for pesky embedded quotes
                        loc values_and_labels_`i' "`values_and_labels_`i''; `val': `curr_value_label'"
                    }
                }
            }
        }
        else {
            if "`=substr("`type_`i''",1,3)'" ==  "str" {         // "
                count_uniq `vname_`i''
                loc distinct_vals_`i' = `r(nv)'
            }
            else {
                loc distinct_vals_`i' = 99999 // set number of distinct values to 99999 if
            }
        }
    }
    clear
    set obs `nrows'
    qui g variable = ""
    qui g type = ""
    qui g var_label = ""
    qui g distinct_vals = .
    qui g vals_and_labels = ""
    forv i = 1/`nrows' {
        qui replace variable        = "`vname_`i''"             if _n == `i'
        qui replace var_label       = "`var_label_`i''"         if _n == `i'
        qui replace distinct_vals   = `distinct_vals_`i''       if _n == `i'
        qui replace type            = "`type_`i''"              if _n == `i'
        qui replace vals_and_labels = "`values_and_labels_`i''" if _n == `i'
    }

end

*! v0.1 Apoorva Lal
// returns dataset with dataset's <describe> output
// useful for very wide datasets / datasets with useless/uninformative
// variable names
// e.g. USAID's Demographic and Health Surveys

pr define varlabelbook
    syntax [anything]
    qui compress
    qui ds `anything'
    loc vl "`r(varlist)'"
    loc nrows: word count `vl'
    forv i = 1/`nrows' {
        loc vname_`i'    :word `i' of `vl'
        loc var_label_`i':var l `vname_`i''
        loc type_`i'     :type `vname_`i''
        if inlist("`type_`i''", "byte","int") {
            count_uniq `vname_`i''
            if `r(nv)' <= 20 {
                loc la_`vname_`i'': val l `vname_`i''
                loc label_exists = cond("`la_`vname_`i'''" != "",1,0)
                if `label_exists'{
                loc values_and_labels_`i' ""
                qui levelsof `vname_`i'', loc(`vname_`i''_l) clean
                    foreach val in ``vname_`i''_l' {
                        loc vlab: label `la_`vname_`i''' `val'
                        loc curr_value_label = subinstr("`vlab'",`"""',"",.)  // " for pesky embedded quotes
                        loc values_and_labels_`i' "`values_and_labels_`i''; `val': `curr_value_label'"
                    }
                }
            }
        }
    }
    clear
    set obs `nrows'
    qui g variable = ""
    qui g type = ""
    qui g var_label = ""
    qui g vals_and_labels = ""
    forv i = 1/`nrows' {
        qui replace variable        = "`vname_`i''"             if _n == `i'
        qui replace var_label       = "`var_label_`i''"         if _n == `i'
        qui replace type            = "`type_`i''"              if _n == `i'
        qui replace vals_and_labels = "`values_and_labels_`i''" if _n == `i'
    }

end


Updated wave.do file with new signals

Updated wave.do file with new signals

onerror {resume}
quietly WaveActivateNextPane {} 0
add wave -noupdate -expand -group {clk and reset} -radix hexadecimal /top_tb/T1/clk
add wave -noupdate -expand -group {clk and reset} -radix hexadecimal /top_tb/T1/reset
add wave -noupdate -group FETCH -radix hexadecimal /top_tb/T1/stall_fetch
add wave -noupdate -group FETCH -radix hexadecimal /top_tb/T1/instr_pc_reg_fetch
add wave -noupdate -group FETCH -radix hexadecimal /top_tb/T1/curr_pc_pc_reg_fetch
add wave -noupdate -group FETCH -radix hexadecimal /top_tb/T1/next_pc_fetch_iss
add wave -noupdate -group FETCH -radix hexadecimal /top_tb/T1/next_seq_pc_pc_reg_fetch
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/valid_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/stall_iss
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/next_seq_pc_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/next_brn_eq_pc_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/next_jmp_pc_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/is_i_type_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/is_j_type_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/is_r_type_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/instr_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/op_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/funct_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/shamt_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/target_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/reg_src_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/reg_dst_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/jump_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/branch_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/mem_read_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/mem_to_reg_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal -childformat {{{/top_tb/T1/alu_op_iss_ex[5]} -radix hexadecimal} {{/top_tb/T1/alu_op_iss_ex[4]} -radix hexadecimal} {{/top_tb/T1/alu_op_iss_ex[3]} -radix hexadecimal} {{/top_tb/T1/alu_op_iss_ex[2]} -radix hexadecimal} {{/top_tb/T1/alu_op_iss_ex[1]} -radix hexadecimal} {{/top_tb/T1/alu_op_iss_ex[0]} -radix hexadecimal}} -subitemconfig {{/top_tb/T1/alu_op_iss_ex[5]} {-height 16 -radix hexadecimal} {/top_tb/T1/alu_op_iss_ex[4]} {-height 16 -radix hexadecimal} {/top_tb/T1/alu_op_iss_ex[3]} {-height 16 -radix hexadecimal} {/top_tb/T1/alu_op_iss_ex[2]} {-height 16 -radix hexadecimal} {/top_tb/T1/alu_op_iss_ex[1]} {-height 16 -radix hexadecimal} {/top_tb/T1/alu_op_iss_ex[0]} {-height 16 -radix hexadecimal}} /top_tb/T1/alu_op_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/mem_wr_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal -childformat {{{/top_tb/T1/alu_src_iss_ex[2]} -radix hexadecimal} {{/top_tb/T1/alu_src_iss_ex[1]} -radix hexadecimal} {{/top_tb/T1/alu_src_iss_ex[0]} -radix hexadecimal}} -subitemconfig {{/top_tb/T1/alu_src_iss_ex[2]} {-height 16 -radix hexadecimal} {/top_tb/T1/alu_src_iss_ex[1]} {-height 16 -radix hexadecimal} {/top_tb/T1/alu_src_iss_ex[0]} {-height 16 -radix hexadecimal}} /top_tb/T1/alu_src_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/reg_wr_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/sign_ext_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/sign_imm_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/sign_ext_iss
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/rd_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/rs_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/rt_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/r_data_p1_rf_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/r_data_p2_rf_iss_ex
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/valid_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/flush_ex
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/branch_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/branch_taken_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/next_brn_eq_pc_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/alu_op_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/alu_src_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/reg_dst_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/mem_to_reg_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/mem_wr_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/reg_wr_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/sign_imm_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/rd_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/rs_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/rt_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/r_data_p1_alu_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/r_data_p1_rf_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/r_data_p2_alu_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/r_data_p2_rf_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/fwd_r_data_p1_alu_ex
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/fwd_r_data_p2_alu_ex
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/res_alu_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/n_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/z_ex_mem
add wave -noupdate -group MEMORY -radix hexadecimal /top_tb/T1/valid_mem_wb
add wave -noupdate -group MEMORY -radix hexadecimal /top_tb/T1/mem_to_reg_mem_wb
add wave -noupdate -group MEMORY -radix hexadecimal /top_tb/T1/mem_wr_mem_wb
add wave -noupdate -group MEMORY -radix hexadecimal /top_tb/T1/reg_wr_mem_wb
add wave -noupdate -group MEMORY -radix hexadecimal /top_tb/T1/rd_mem_wb
add wave -noupdate -group MEMORY -radix hexadecimal /top_tb/T1/res_alu_mem_wb
add wave -noupdate -group MEMORY -radix hexadecimal /top_tb/T1/read_data_dmem_ram_mem_wb
add wave -noupdate -group WRITE-BACK -radix hexadecimal /top_tb/T1/valid_wb_ret
add wave -noupdate -group WRITE-BACK -radix hexadecimal /top_tb/T1/mem_to_reg_wb_ret
add wave -noupdate -group WRITE-BACK -radix hexadecimal /top_tb/T1/reg_wr_wb_ret
add wave -noupdate -group WRITE-BACK -radix hexadecimal /top_tb/T1/rd_wb_ret
add wave -noupdate -group WRITE-BACK -radix hexadecimal /top_tb/T1/res_alu_wb_ret
add wave -noupdate -group WRITE-BACK -radix hexadecimal /top_tb/T1/read_data_wb_ret
add wave -noupdate -group WRITE-BACK -radix hexadecimal /top_tb/T1/wr_data_rf_wb_ret
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/clk
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/r_data_p1
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/r_data_p1_rf_o
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/r_data_p2
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/r_data_p2_rf_o
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/r_reg_p1_rf_i
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/r_reg_p2_rf_i
add wave -noupdate -group RF -radix hexadecimal -childformat {{{/top_tb/T1/R1/reg_file[31]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[30]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[29]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[28]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[27]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[26]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[25]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[24]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[23]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[22]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[21]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[20]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[19]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[18]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[17]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[16]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[15]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[14]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[13]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[12]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[11]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[10]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[9]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[8]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[7]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[6]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[5]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[4]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[3]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[2]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[1]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[0]} -radix hexadecimal}} -subitemconfig {{/top_tb/T1/R1/reg_file[31]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[30]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[29]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[28]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[27]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[26]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[25]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[24]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[23]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[22]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[21]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[20]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[19]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[18]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[17]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[16]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[15]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[14]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[13]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[12]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[11]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[10]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[9]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[8]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[7]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[6]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[5]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[4]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[3]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[2]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[1]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[0]} {-height 16 -radix hexadecimal}} /top_tb/T1/R1/reg_file
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/reset
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/w_data_rf_i
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/w_en_rf_i
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/w_reg_rf_i
add wave -noupdate -group ALU -radix hexadecimal /top_tb/T1/A1/opr_a_alu_i
add wave -noupdate -group ALU -radix hexadecimal /top_tb/T1/A1/opr_b_alu_i
add wave -noupdate -group ALU -radix hexadecimal /top_tb/T1/A1/op_alu_i
add wave -noupdate -group ALU -radix hexadecimal /top_tb/T1/A1/res_alu_o
add wave -noupdate -group ALU -radix hexadecimal /top_tb/T1/A1/n_alu_o
add wave -noupdate -group ALU -radix hexadecimal /top_tb/T1/A1/z_alu_o
add wave -noupdate -group HAZARD -radix hexadecimal /top_tb/T1/hazard/fwd_p1_ex_mem_hz_o
add wave -noupdate -group HAZARD -radix hexadecimal /top_tb/T1/hazard/fwd_p2_ex_mem_hz_o
add wave -noupdate -group HAZARD /top_tb/T1/flush_iss
add wave -noupdate -group HAZARD -radix hexadecimal /top_tb/T1/hazard/flush_ex_hz_o
add wave -noupdate -group HAZARD -radix hexadecimal /top_tb/T1/hazard/stall_fetch_hz_o
add wave -noupdate -group HAZARD -radix hexadecimal /top_tb/T1/hazard/stall_iss_hz_o
TreeUpdate [SetDefaultTree]
WaveRestoreCursors {{Cursor 1} {380 ps} 0}
quietly wave cursor active 1
configure wave -namecolwidth 325
configure wave -valuecolwidth 243
configure wave -justifyvalue left
configure wave -signalnamewidth 0
configure wave -snapdistance 10
configure wave -datasetprefix 0
configure wave -rowmargin 4
configure wave -childrowmargin 2
configure wave -gridoffset 0
configure wave -gridperiod 1
configure wave -griddelta 40
configure wave -timeline 0
configure wave -timelineunits ns
update
WaveRestoreZoom {156 ps} {476 ps}

onerror {resume}
quietly WaveActivateNextPane {} 0
add wave -noupdate -expand -group {clk and reset} -radix hexadecimal /top_tb/T1/clk
add wave -noupdate -expand -group {clk and reset} -radix hexadecimal /top_tb/T1/reset
add wave -noupdate -group FETCH -radix hexadecimal /top_tb/T1/stall_fetch
add wave -noupdate -group FETCH -radix hexadecimal /top_tb/T1/instr_pc_reg_fetch
add wave -noupdate -group FETCH -radix hexadecimal /top_tb/T1/curr_pc_pc_reg_fetch
add wave -noupdate -group FETCH -radix hexadecimal /top_tb/T1/next_pc_fetch_iss
add wave -noupdate -group FETCH -radix hexadecimal /top_tb/T1/next_seq_pc_pc_reg_fetch
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/valid_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/stall_iss
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/next_pc_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/next_beq_pc_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/next_beq_pc_carry_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/is_i_type_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/is_j_type_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/is_r_type_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/instr_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/op_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/funct_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/shamt_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/target_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/reg_src_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/reg_dst_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/jump_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/branch_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/mem_read_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/mem_to_reg_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal -childformat {{{/top_tb/T1/alu_op_iss_ex[5]} -radix hexadecimal} {{/top_tb/T1/alu_op_iss_ex[4]} -radix hexadecimal} {{/top_tb/T1/alu_op_iss_ex[3]} -radix hexadecimal} {{/top_tb/T1/alu_op_iss_ex[2]} -radix hexadecimal} {{/top_tb/T1/alu_op_iss_ex[1]} -radix hexadecimal} {{/top_tb/T1/alu_op_iss_ex[0]} -radix hexadecimal}} -subitemconfig {{/top_tb/T1/alu_op_iss_ex[5]} {-height 16 -radix hexadecimal} {/top_tb/T1/alu_op_iss_ex[4]} {-height 16 -radix hexadecimal} {/top_tb/T1/alu_op_iss_ex[3]} {-height 16 -radix hexadecimal} {/top_tb/T1/alu_op_iss_ex[2]} {-height 16 -radix hexadecimal} {/top_tb/T1/alu_op_iss_ex[1]} {-height 16 -radix hexadecimal} {/top_tb/T1/alu_op_iss_ex[0]} {-height 16 -radix hexadecimal}} /top_tb/T1/alu_op_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/mem_wr_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal -childformat {{{/top_tb/T1/alu_src_iss_ex[2]} -radix hexadecimal} {{/top_tb/T1/alu_src_iss_ex[1]} -radix hexadecimal} {{/top_tb/T1/alu_src_iss_ex[0]} -radix hexadecimal}} -subitemconfig {{/top_tb/T1/alu_src_iss_ex[2]} {-height 16 -radix hexadecimal} {/top_tb/T1/alu_src_iss_ex[1]} {-height 16 -radix hexadecimal} {/top_tb/T1/alu_src_iss_ex[0]} {-height 16 -radix hexadecimal}} /top_tb/T1/alu_src_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/reg_wr_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/sign_ext_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/sign_imm_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/sign_ext_iss
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/rd_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/rs_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/rt_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/r_data_p1_rf_iss_ex
add wave -noupdate -group ISSUE -radix hexadecimal /top_tb/T1/r_data_p2_rf_iss_ex
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/valid_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/flush_ex
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/alu_op_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/alu_src_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/reg_dst_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/mem_to_reg_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/mem_wr_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/reg_wr_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/sign_imm_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/rd_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/rs_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/rt_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/r_data_p1_alu_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/r_data_p1_rf_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/r_data_p2_alu_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/r_data_p2_rf_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/fwd_r_data_p1_alu_ex
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/fwd_r_data_p2_alu_ex
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/res_alu_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/n_ex_mem
add wave -noupdate -group EXECUTE -radix hexadecimal /top_tb/T1/z_ex_mem
add wave -noupdate -group MEMORY -radix hexadecimal /top_tb/T1/valid_mem_wb
add wave -noupdate -group MEMORY -radix hexadecimal /top_tb/T1/mem_to_reg_mem_wb
add wave -noupdate -group MEMORY -radix hexadecimal /top_tb/T1/mem_wr_mem_wb
add wave -noupdate -group MEMORY -radix hexadecimal /top_tb/T1/reg_wr_mem_wb
add wave -noupdate -group MEMORY -radix hexadecimal /top_tb/T1/rd_mem_wb
add wave -noupdate -group MEMORY -radix hexadecimal /top_tb/T1/res_alu_mem_wb
add wave -noupdate -group MEMORY -radix hexadecimal /top_tb/T1/read_data_dmem_ram_mem_wb
add wave -noupdate -group WRITE-BACK -radix hexadecimal /top_tb/T1/valid_wb_ret
add wave -noupdate -group WRITE-BACK -radix hexadecimal /top_tb/T1/mem_to_reg_wb_ret
add wave -noupdate -group WRITE-BACK -radix hexadecimal /top_tb/T1/reg_wr_wb_ret
add wave -noupdate -group WRITE-BACK -radix hexadecimal /top_tb/T1/rd_wb_ret
add wave -noupdate -group WRITE-BACK -radix hexadecimal /top_tb/T1/res_alu_wb_ret
add wave -noupdate -group WRITE-BACK -radix hexadecimal /top_tb/T1/read_data_wb_ret
add wave -noupdate -group WRITE-BACK -radix hexadecimal /top_tb/T1/wr_data_rf_wb_ret
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/clk
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/r_data_p1
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/r_data_p1_rf_o
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/r_data_p2
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/r_data_p2_rf_o
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/r_reg_p1_rf_i
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/r_reg_p2_rf_i
add wave -noupdate -group RF -radix hexadecimal -childformat {{{/top_tb/T1/R1/reg_file[31]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[30]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[29]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[28]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[27]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[26]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[25]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[24]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[23]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[22]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[21]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[20]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[19]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[18]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[17]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[16]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[15]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[14]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[13]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[12]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[11]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[10]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[9]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[8]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[7]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[6]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[5]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[4]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[3]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[2]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[1]} -radix hexadecimal} {{/top_tb/T1/R1/reg_file[0]} -radix hexadecimal}} -subitemconfig {{/top_tb/T1/R1/reg_file[31]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[30]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[29]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[28]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[27]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[26]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[25]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[24]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[23]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[22]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[21]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[20]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[19]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[18]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[17]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[16]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[15]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[14]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[13]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[12]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[11]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[10]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[9]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[8]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[7]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[6]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[5]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[4]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[3]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[2]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[1]} {-height 16 -radix hexadecimal} {/top_tb/T1/R1/reg_file[0]} {-height 16 -radix hexadecimal}} /top_tb/T1/R1/reg_file
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/reset
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/w_data_rf_i
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/w_en_rf_i
add wave -noupdate -group RF -radix hexadecimal /top_tb/T1/R1/w_reg_rf_i
add wave -noupdate -group ALU -radix hexadecimal /top_tb/T1/A1/opr_a_alu_i
add wave -noupdate -group ALU -radix hexadecimal /top_tb/T1/A1/opr_b_alu_i
add wave -noupdate -group ALU -radix hexadecimal /top_tb/T1/A1/op_alu_i
add wave -noupdate -group ALU -radix hexadecimal /top_tb/T1/A1/res_alu_o
add wave -noupdate -group ALU -radix hexadecimal /top_tb/T1/A1/n_alu_o
add wave -noupdate -group ALU -radix hexadecimal /top_tb/T1/A1/z_alu_o
TreeUpdate [SetDefaultTree]
WaveRestoreCursors {{Cursor 1} {1500 ps} 0}
quietly wave cursor active 1
configure wave -namecolwidth 325
configure wave -valuecolwidth 243
configure wave -justifyvalue left
configure wave -signalnamewidth 0
configure wave -snapdistance 10
configure wave -datasetprefix 0
configure wave -rowmargin 4
configure wave -childrowmargin 2
configure wave -gridoffset 0
configure wave -gridperiod 1
configure wave -griddelta 40
configure wave -timeline 0
configure wave -timelineunits ns
update
WaveRestoreZoom {1418 ps} {1620 ps}


Update reghdfe.ado

Update reghdfe.ado


iedropone : mvar string and comment

iedropone : mvar string and comment

Inmplemented string support for mvar(). Cleaned up test output and added
descriptive comments

	capture program drop 	iedropone
			program define 	iedropone ,

	qui {

		syntax [if] ,  [Numobs(numlist int min=1 max=1 >0) mvar(varname) mval(string) zerook]

		version 11.0

		/***********************************

			Set constants

		***********************************/

		*Set a constant for the multi option being used
												local MULTI_USED 0
		if ("`mvar'" != "" & "`mval'" != "") 	local MULTI_USED 1

		*Set a constant for the zerook option being used
												local ZEROOK_USED 0
		if ("`zerook'" != "") 					local ZEROOK_USED 1

		*Set a constant for if an IF-condition used
												local IF_USED 0
		if ("`if'" != "") 						local IF_USED 1

		/***********************************

			Test input

		***********************************/

		*Test that mvar() and mval() was used in combination
		if ("`mvar'" != "" & "`mval'" == "") {

			di as error "{pstd}The option mval() is required when using the option mvar()"
			error 197
		}
		if ("`mvar'" == "" & "`mval'" != "") {

			di as error "{pstd}The option mvar() is required when using the option mval()"
			error 197
		}

		*Test that either an if condition was specified or of the multi values option was used
		if `IF_USED' == 0 & `MULTI_USED' == 0 {

			di as error "{pstd}An {it:if} condition is required when mvar() and mval() is not used."
			error 197
		}

		/***********************************

			Set locals

		***********************************/

		*If number of obs to drop is not set, then use the default which is 1
		if "`numobs'" == "" {

			local numobs = 1
		}

		*Test if the var in mvar() is string or not
		if `MULTI_USED' == 1 {

			cap confirm string variable `mvar'

			if _rc == 0	local MULTI_STRING 1
			if _rc != 0	local MULTI_STRING 0
		}

		/***********************************

			Test the number of obs matching

		***********************************/

		*Subfunction options
		local subfunc_opts "nobs(`numobs') zero(`ZEROOK_USED')"

		if `MULTI_USED' == 0 {

			** Use the functon iedropone_test_match to
			*  test if the number of observations to drop
			*  is correct
			iedropone_test_match `if' , `subfunc_opts'
			local num_obs_dropped `r(numtodrop)'

		}
		else {

			**Create a counter that will noitify
			* the user how many observations were
			* dropped
			local num_obs_dropped = 0

			*Loop over all values in mval()
			foreach mvalue of local mval {

				*Run the sub-function that test number of observation to be dropped is OK

				*Is mvar() is numeric
				if `MULTI_STRING' == 0 {

					** Use the functon iedropone_test_match to
					*  test if the number of observations to drop
					*  is correct
					if `IF_USED' == 1 	iedropone_test_match `if' & `mvar' == `mvalue'   , `subfunc_opts'
					if `IF_USED' == 0	iedropone_test_match  if 	`mvar' == `mvalue'   , `subfunc_opts'
				}
				*Is mvar() is numeric
				else {

					** Use the functon iedropone_test_match to
					*  test if the number of observations to drop
					*  is correct
					if `IF_USED' == 1 	iedropone_test_match `if' & `mvar' == "`mvalue'" , `subfunc_opts'
					if `IF_USED' == 0	iedropone_test_match  if 	`mvar' == "`mvalue'" , `subfunc_opts'

				}

				*Add to teh counter how many observations will be dropped
				local num_obs_dropped = `num_obs_dropped' + `r(numtodrop)'
			}
		}

		/***********************************

			Drop observation(s)

		***********************************/

		*Test if multivars are used
		if `MULTI_USED' == 0 {

			*The observations to be dropped
			drop `if'

		}
		else {

			*Loop over all values in mval and drop observations
			foreach mvalue of local mval {

				if `MULTI_STRING' == 0 {
					if `IF_USED' == 1 	drop `if' & `mvar' == `mvalue'
					if `IF_USED' == 0	drop  if 	`mvar' == `mvalue'
				}
				else {
					if `IF_USED' == 1 	drop `if' & `mvar' == "`mvalue'"
					if `IF_USED' == 0	drop  if 	`mvar' == "`mvalue'"
				}
			}
		}

		*Output to user how many observations were dropped
		if `num_obs_dropped' == 1 noi di "`num_obs_dropped' observation was dropped"
		if `num_obs_dropped' != 1 noi di "`num_obs_dropped' observations were dropped"

	}

	end

	**Sub function that checks that the number of obswervations
	* to drop is correct and it returns the number of obsevations
	* that will be dropped.

	capture program drop 	iedropone_test_match
			program define 	iedropone_test_match , rclass

		syntax [if] , nobs(int) zero(int)

		**Count how many obs fits the drop condition (this
		* function is called once for each value in mval)
		count `if'
		local count_match `r(N)'

		*Test if no match and zerook not used
		if `count_match' == 0 & `zero' == 0 {

			*Return error message
			noi di as error `"{pstd}No observation matches the drop condition " `if'". Consider using option zerook to surpress this error. No observations dropped."'
			error 2000
		}
		*Test if no match but zerook used
		else if `count_match' == 0 & `zero' == 1 {

			*No observation dropped but that is allowed byt zero_used. Return 0.
			return scalar numtodrop	= `count_match'

		}
		*Test if the number of match is less than it is supposed to be
		else if `count_match' < `nobs' {

			*Return error message
			noi di as error  `"{pstd}There are less than exactly `nobs' observations that match the drop condition " `if'". No observations dropped."'
			error 910

		}
		*Test if the number of match is more than it is supposed to be
		else if `count_match' > `nobs' {

			*Return error message
			if `nobs' == 1  noi di as error  `"{pstd}There are more than exactly `nobs' observation that match the drop condition " `if'". No observations dropped."'
			if `nobs' >  1  noi di as error  `"{pstd}There are more than exactly `nobs' observations that match the drop condition " `if'". No observations dropped."'
			error 912

		}
		*Test if the number of match exactly what it is suppsed to be
		else if `count_match' == `nobs' {

			*Return the number of obs that will be dropped
			return scalar numtodrop	= `count_match'

		}
		*The options above should be mutually exclusive, so this should never happen.
		else {

			*Return error message
			noi di as error "{pstd}The command is never supposed to reach this point, please notify the author if the command on kbjarkefur@worldbank.org"
			error 197
		}

	end

	capture program drop 	iedropone
			program define 	iedropone ,

	qui {

		*noi di "command OK!"

		syntax [if] ,  [Numobs(numlist int min=1 max=1 >0) mvar(varname) mval(string) zerook]

		*noi di "syntax OK!"

		*noi di "`if'"

		version 11.0

		/***********************************

			Set constants

		***********************************/

		*Set a constant for the multi option being used
												local MULTI_USED 0
		if ("`mvar'" != "" & "`mval'" != "") 	local MULTI_USED 1

		*Set a constant for the zerook option being used
												local ZEROOK_USED 0
		if ("`zerook'" != "") 					local ZEROOK_USED 1

		*Set a constant for if an IF-condition used
												local IF_USED 0
		if ("`if'" != "") 						local IF_USED 1

		/***********************************

			Test input

		***********************************/

		*Test that mvar() and mval() was used in combination
		if ("`mvar'" != "" & "`mval'" == "") {

			di as error "{pstd}The options mval() is required when using the option mvar()"
			error 197
		}
		if ("`mvar'" == "" & "`mval'" != "") {

			di as error "{pstd}The options mvar() is required when using the option mval()"
			error 197
		}

		*Test that either an if condition was specified or of the multi values option was used
		if `IF_USED' == 0 & `MULTI_USED' == 0 {

			di as error "{pstd}An {it:if} condition is required unless mvar() and mval() is used."
			error 197
		}

		/***********************************

			Set locals

		***********************************/

		*If number of drops is not set, tehn use the default which is 1
		if "`numobs'" == "" {

			local numobs = 1
		}

		/***********************************

			Test the number of obs matching

		***********************************/

		*noi di "Test the number of obs matching"

		if `MULTI_USED' == 0 {

			noi di "iedropone_test_match `if' , numobs(`numobs') zero_used(`ZEROOK_USED')"

			iedropone_test_match `if' , numobs(`numobs') zero_used(`ZEROOK_USED') multi_used(`MULTI_USED')
			local num_obs_dropped `r(numtodrop)'

		}
		else {

			local num_obs_dropped = 0

			foreach mvalue in `mval' {

				if `IF_USED' == 1	noi di "iedropone_test_match `if' & `mvar' == `mvalue' , numobs(`numobs') zero_used(`ZEROOK_USED')"
				if `IF_USED' == 0	noi di "iedropone_test_match  if 	`mvar' == `mvalue' , numobs(`numobs') zero_used(`ZEROOK_USED')"

				if `IF_USED' == 1 	iedropone_test_match `if' & `mvar' == `mvalue' , numobs(`numobs') zero_used(`ZEROOK_USED') multi_used(`MULTI_USED')
				if `IF_USED' == 0	iedropone_test_match  if 	`mvar' == `mvalue' , numobs(`numobs') zero_used(`ZEROOK_USED') multi_used(`MULTI_USED')

				local num_obs_dropped = `num_obs_dropped' + `r(numtodrop)'
			}
		}

		/***********************************

			Drop observation(s)

		***********************************/

		*noi di "Drop observation(s)"

		if `MULTI_USED' == 0 {

			drop `if'
		}
		else {
			foreach mvalue in `mval' {

				if `IF_USED' == 1 	drop `if' & `mvar' == `mvalue'
				if `IF_USED' == 0	drop  if 	`mvar' == `mvalue'
			}
		}

		if `num_obs_dropped' == 1 {

			noi di "`num_obs_dropped' observation was dropped"
		}
		else {
			noi di "`num_obs_dropped' observations were dropped"
		}
	}

	end

	capture program drop 	iedropone_test_match
			program define 	iedropone_test_match , rclass

		syntax [if] , numobs(int) zero_used(int) multi_used(int)

		*Count how many obs fits this
		count `if'

		local count_match `r(N)'

		if `count_match' == 0 & `zero_used' == 0 {

			noi di as error `"{pstd}No observation matches the drop condition " `if'". Consider using option zerook to surpress this error. No observations dropped."'
			error 2000
		}
		else if `count_match' == 0 & `zero_used' == 1 {

			*No observation dropped but that is allowed byt zero_used
			return scalar numtodrop	= `count_match'

		}

		else if `count_match' < `numobs' {

			noi di as error  `"{pstd}There are less than exactly `numobs' observations that match the drop condition " `if'". No observations dropped."'
			error 910

		}
		else if `count_match' > `numobs' {

			if `numobs' == 1  noi di as error  `"{pstd}There are more than exactly `numobs' observation that match the drop condition " `if'". No observations dropped."'
			if `numobs' >  1  noi di as error  `"{pstd}There are more than exactly `numobs' observations that match the drop condition " `if'". No observations dropped."'
			error 912

		}
		else if `count_match' == `numobs' {

			return scalar numtodrop	= `count_match'

		}
		else {

			noi di as error "{pstd}The command is never supposed to reach this point, please notify the author iof the command on kbjarkefur@worldbank.org"
			error 197
		}

	end


iefolder : typo in output

iefolder : typo in output

cap program drop 	iefolder
	program define	iefolder

qui {

	syntax anything, PROJectfolder(string) [ABBreviation(string)]

	***Todo
	*Test that old master do file exist

	*Create an empty line before error message or output
	noi di ""

	/***************************************************

		Parse input

	***************************************************/

	*Parse out the sub-command
	gettoken subcommand item : anything

	*Parse out the item type and the item name
	gettoken itemType itemName : item

	*Make sure that the item name is only one word
	gettoken itemName rest : itemName

	*Clean up the input
	local subcomand = trim("`subcommand'")
	local itemType 	= trim("`itemType'")
	local itemName 	= trim("`itemName'")

	*noi di "SubCommand 	`subcommand'"
	*noi di "ItemType 	`itemType'"
	*noi di "ItemName	`itemName'"

	*test that there is no space in itemname
	local space_pos = strpos(trim("`itemName'"), " ")

	if "`rest'" != ""  | "`space_pos'" != 0 {

		noi di as error "{pstd}You have specified to many words in: [{it:iefolder `subcommand' `itemType' `itemName'`rest'}] or used a space in {it:itemname}. Spaces are not allowed in the {it:itemname}. Use underscores or camel case.{p_end}"
		error 198
	}

	 /***************************************************

		Test input

	***************************************************/

	local sub_commands "new"
	local itemTypes "project round master"

	*Test if subcommand is valid
	if `:list subcommand in sub_commands' == 0 {

		noi di as error "{phang}You have not used a valid subcommand. See help file for details.{p_end}"
		error 198
	}

	*Test if item type is valid
	if `:list itemType in itemTypes' == 0 {

		noi di as error "{phang}You have not used a valid item type. See help file for details.{p_end}"
		error 198
	}

	*Test that item name is used when item type is anything but project
	else if ("`itemType'" != "project" & "`itemName'" == "" ) {

		noi di as error "{phang}You must specify a name of the `itemType'. See help file for details.{p_end}"
		error 198
	}

	di "All tests ok"

	/***************************************************

		Start making updates to the project folder

	***************************************************/

	*Create a temporary textfile
	tempname 	newHandle
	tempfile	newTextFile

	cap file close 	`newHandle'
		file open  	`newHandle' using "`newTextFile'", text write append

	*Create a global pointing to the main data folder
	global dataWorkFolder 	"`projectfolder'/DataWork"
	global encryptFolder 	"$dataWorkFolder/EncryptedData"

	if "`subcommand'" == "new" {

		di "Subcommand: New"

		*Creating a new project
		if "`itemType'" == "project" {

			di "ItemType: Project"
			iefolder_newProject "`projectfolder'" `newHandle'
			noi di "{pstd}Command ran succesfully, a new DataWork folder was created here:{p_end}"
			noi di "{pstd}1) [${dataWorkFolder}]{p_end}"

		}
		*Creating a new round
		else if "`itemType'" == "round" {

			*Use the full item name if abbrevaition was not specified
			if "`abbreviation'" == "" local abbreviation "`itemName'"

			di "ItemType: round"
			iefolder_newRound `newHandle' "`itemName'" "`abbreviation'"

			noi di "{pstd}Command ran succesfully, for the round `itemName' the following folders and master dofile were created:{p_end}"
			noi di "{pstd}1) [${`abbreviation'}]{p_end}"
			noi di "{pstd}2) [${encryptFolder}/`itemName' Encrypted Data]{p_end}"
			noi di "{pstd}3) [${`abbreviation'}/`itemName'_MasterDofile.do]{p_end}"
		}
		*Creating a new level of observation for master data set
		else if "`itemType'" == "master" {

			di "ItemType: master/unitofobs"
			di `"iefolder_newMaster	`newHandle' "`itemName'""'
			iefolder_newMaster	`newHandle' "`itemName'"

			noi di "{pstd}Command ran succesfully, for the master `itemName' the following folders were created:{p_end}"
			noi di "{pstd}1) [${dataWorkFolder}/MasterData/`itemName']{p_end}"
			noi di "{pstd}2) [${encryptFolder}/IDMasterKey/`itemName']{p_end}"
		}
	}

	*Closing the new main master dofile handle
	file close 		`newHandle'

	*Copy the new master dofile from the tempfile to the original position
	copy "`newTextFile'"  "$dataWorkFolder/Project_MasterDofile.do" , replace
}
end

	/***************************************************

		Here are all functions for combination of
		subcommand and item type

	***************************************************/

cap program drop 	iefolder_newProject
	program define	iefolder_newProject

		args projectfolder newHandle

		*Test if folder where to create new folder exist
		checkFolderExists "`projectfolder'" "parent"

		*Test that the new folder does not already exist
		checkFolderExists "$dataWorkFolder" "new"

		mkdir "$dataWorkFolder"

		******************************
		*Writing master do file header
		******************************

		*Write intro part with description of project,
		mdofle_p0 `newHandle' project

		*Write flolder globals section header and the root folders
		mdofle_p1 `newHandle' "`projectfolder'"

		*Write globals section header and the root folders
		mdofle_p2 `newHandle'

		*Write section that runs sub-master dofiles
		mdofle_p3 `newHandle' project

end

cap program drop 	iefolder_newRound
	program define	iefolder_newRound

	args subHandle rndName rndAbb

	di "new round command"

	*Test if folder where to create new folder exist
	checkFolderExists "$dataWorkFolder" "parent"

	*Test that the new folder does not already exist
	checkFolderExists "$dataWorkFolder/`rndName'" "new"

	*Old file reference
	tempname 	oldHandle
	local 		oldTextFile 	"$dataWorkFolder/Project_MasterDofile.do"

	file open `oldHandle' using `"`oldTextFile'"', read
	file read `oldHandle' line

	*Locals needed for the section devider
	local partNum 		= 0 //Keeps track of the part number

	while r(eof)==0 {

		*Do not interpret macros
		local line : subinstr local line "\$"  "\\$"
		local line : subinstr local line "\`"  "\\`"

		parseReadLine `"`line'"'

		if `r(ief_line)' == 0 {

			*This is a regular line of code. It should be copied as-is. No action needed.
			file write	`subHandle' `"`line'"' _n

		}
		else if `r(ief_line)' == 1 {

			**This is a line of code with a devisor written by
			* iefodler. New additions to a section are always added right before an end of section line.

			*return list

			**This is NOT an end of section line. Nothing will be written here
			* but we test that there is no confict with previous names
			if `r(ief_end)' == 0 {

					*Test if it is an end of globals section as we are writing a new
					if "`r(sectionName)'" == "monitor" {

					*Write devisor for this section
					writeDevisor 			`subHandle' 1 RoundGlobals rounds `rndName' `rndAbb'

					*Write the globals to the master do file and create the folders
					newRndFolderAndGlobals 	`rndName' `rndAbb' "dataWorkFolder" `subHandle'

					*Write an empty line before the end devisor
					file write		`subHandle' "" _n

				}
				else {

					*Test that the folder name about to be used is not already in use
					if "`r(itemName)'" == "`rndName'" {
						noi di as error "{phang}The new round name `rndName' is already in use. No new folders are creaetd and the master do-files has not been changed.{p_end}"
						error 507
					}

					*Test that the folder name about to be used is not already in use
					if "`r(itemAbb)'" == "`rndAbb'" {
						noi di as error "{phang}The new round abbreviation `rndAbb' is already in use. No new folders are creaetd and the master do-files has not been changed.{p_end}"
						error 507
					}

				}

				*Copy the line as is
				file write		`subHandle' `"`line'"' _n
			}

			**This is an end of section line. We will add the new content here
			* before writing the end of section line
			else if `r(ief_end)' == 1 {

				*Test if it is an end of globals section as we are writing a new
				if "`r(partName)'" == "End_RunDofiles" {

					*Write devisor for this section
					writeDevisor 			`subHandle' 3 RunDofiles `rndName' `rndAbb'

					*Write the
					file write  `subHandle' ///
						_col(4)"if (0) { //Change the 0 to 1 to run the `rndName' master dofile" _n ///
						_col(8) `"do ""' _char(36) `"`rndAbb'/`rndName'_MasterDofile.do" "' _n ///
						_col(4)"}" ///
						_n

					*Write an empty line before the end devisor
					file write		`subHandle' "" _n

				}

				*Write the end of section line
				file write		`subHandle' `"`line'"' _n
			}
		}

		*Read next file and repeat the while loop
		file read `oldHandle' line
	}

	*Close the old file.
	file close `oldHandle'

end

cap program drop 	iefolder_newMaster
	program define	iefolder_newMaster

	args subHandle obsName

	di "new master command"

	global mastData 		"$dataWorkFolder/MasterData"
	global mastDataIDKey 	"$encryptFolder/IDMasterKey"

	*********************************************
	*Test if folder can be created where expected
	*********************************************

	*Test if folder where to create new folder exist
	checkFolderExists "$mastDataIDKey" "parent"

	*Test that the new folder does not already exist
	checkFolderExists "$mastDataIDKey/`obsName'" "new"

	*Test if folder where to create new fodler exist
	checkFolderExists "$mastData" "parent"

	*Test that the new folder does not already exist
	checkFolderExists "$mastData/`obsName'" "new"

	*************
	*create folder in masterdata

	*Old file reference
	tempname 	oldHandle
	local 		oldTextFile 	"$dataWorkFolder/Project_MasterDofile.do"

	file open `oldHandle' using `"`oldTextFile'"', read
	file read `oldHandle' line

	*Locals needed for the section devider
	local partNum 		= 0 //Keeps track of the part number

	while r(eof)==0 {

		*Do not interpret macros
		local line : subinstr local line "\$"  "\\$"
		local line : subinstr local line "\`"  "\\`"

		parseReadLine `"`line'"'

		if `r(ief_line)' == 1 & `r(ief_line)' == 1 & `r(ief_end)' == 0  & "`r(sectionName)'" == "rawData" {

			*Create master data folder and add global to folder in master do file
			cap createFolderWriteGlobal "`obsName'"  "mastData"  	mastData_`obsName'	`subHandle'

			if _rc == 693 {

				*If that folder exist, problem
				noi di as error "{phang}could not create new folder, folder name might already exist "
				error _rc

			}
			else if _rc != 0 {

				*Unexpected error, run the exact command name again and throw the error to user
				createFolderWriteGlobal "`obsName'"  "mastData"  	mastData_`obsName'	`subHandle'
			}

			file write		`subHandle' `"`line'"' _n

		}
		else {

			*Copy the line as is
			file write		`subHandle' `"`line'"' _n

		}

		*Read next file and repeat the while loop
		file read `oldHandle' line
	}

	*Close the old file.
	file close `oldHandle'

	*Create master data subfolders
	createFolderWriteGlobal "MasterDataSets"  	"mastData_`obsName'"  masterDataSets
	createFolderWriteGlobal "Dofiles"  			"mastData_`obsName'"  mastDataDo

		*************
	*create folder in encrypred ID key master

	createFolderWriteGlobal "`obsName'"  		"mastDataIDKey"  			mastData_E_`obsName'
	createFolderWriteGlobal "Data"  			"mastData_E_`obsName'"  	mastData_E_data
	createFolderWriteGlobal "Sampling"  		"mastData_E_`obsName'"  	mastData_E_Samp
	createFolderWriteGlobal "Treatment"  		"mastData_E_`obsName'"  	mastData_E_Treat

end

cap program drop 	iefolder
	program define	iefolder

qui {

	syntax anything, PROJectfolder(string) [ABBreviation(string)]

	***Todo
	*Test that old master do file exist

	*Create an empty line before error message or output
	noi di ""

	/***************************************************

		Parse input

	***************************************************/

	*Parse out the sub-command
	gettoken subcommand item : anything

	*Parse out the item type and the item name
	gettoken itemType itemName : item

	*Make sure that the item name is only one word
	gettoken itemName rest : itemName

	*Clean up the input
	local subcomand = trim("`subcommand'")
	local itemType 	= trim("`itemType'")
	local itemName 	= trim("`itemName'")

	*noi di "SubCommand 	`subcommand'"
	*noi di "ItemType 	`itemType'"
	*noi di "ItemName	`itemName'"

	*test that there is no space in itemname
	local space_pos = strpos(trim("`itemName'"), " ")

	if "`rest'" != ""  | "`space_pos'" != 0 {

		noi di as error "{pstd}You have specified to many words in: [{it:iefolder `subcommand' `itemType' `itemName'`rest'}] or used a space in {it:itemname}. Spaces are not allowed in the {it:itemname}. Use underscores or camel case.{p_end}"
		error 198
	}

	 /***************************************************

		Test input

	***************************************************/

	local sub_commands "new"
	local itemTypes "project round master"

	*Test if subcommand is valid
	if `:list subcommand in sub_commands' == 0 {

		noi di as error "{phang}You have not used a valid subcommand. See help file for details.{p_end}"
		error 198
	}

	*Test if item type is valid
	if `:list itemType in itemTypes' == 0 {

		noi di as error "{phang}You have not used a valid item type. See help file for details.{p_end}"
		error 198
	}

	*Test that item name is used when item type is anything but project
	else if ("`itemType'" != "project" & "`itemName'" == "" ) {

		noi di as error "{phang}You must specify a name of the `itemType'. See help file for details.{p_end}"
		error 198
	}

	di "All tests ok"

	/***************************************************

		Start making updates to the project folder

	***************************************************/

	*Create a temporary textfile
	tempname 	newHandle
	tempfile	newTextFile

	cap file close 	`newHandle'
		file open  	`newHandle' using "`newTextFile'", text write append

	*Create a global pointing to the main data folder
	global dataWorkFolder 	"`projectfolder'/DataWork"
	global encryptFolder 	"$dataWorkFolder/EncryptedData"

	if "`subcommand'" == "new" {

		di "Subcommand: New"

		*Creating a new project
		if "`itemType'" == "project" {

			di "ItemType: Project"
			iefolder_newProject "`projectfolder'" `newHandle'
			noi di "{pstd}Command ran succesfully, a new DataWork folder was created here created:{p_end}"
			noi di "{pstd}1) [${dataWorkFolder}]{p_end}"

		}
		*Creating a new round
		else if "`itemType'" == "round" {

			*Use the full item name if abbrevaition was not specified
			if "`abbreviation'" == "" local abbreviation "`itemName'"

			di "ItemType: round"
			iefolder_newRound `newHandle' "`itemName'" "`abbreviation'"

			noi di "{pstd}Command ran succesfully, for the round `itemName' the following folders and master dofile were created:{p_end}"
			noi di "{pstd}1) [${`abbreviation'}]{p_end}"
			noi di "{pstd}2) [${encryptFolder}/`itemName' Encrypted Data]{p_end}"
			noi di "{pstd}3) [${`abbreviation'}/`itemName'_MasterDofile.do]{p_end}"
		}
		*Creating a new level of observation for master data set
		else if "`itemType'" == "master" {

			di "ItemType: master/unitofobs"
			di `"iefolder_newMaster	`newHandle' "`itemName'""'
			iefolder_newMaster	`newHandle' "`itemName'"

			noi di "{pstd}Command ran succesfully, for the master `itemName' the following folders were created:{p_end}"
			noi di "{pstd}1) [${dataWorkFolder}/MasterData/`itemName']{p_end}"
			noi di "{pstd}2) [${encryptFolder}/IDMasterKey/`itemName']{p_end}"
		}
	}

	*Closing the new main master dofile handle
	file close 		`newHandle'

	*Copy the new master dofile from the tempfile to the original position
	copy "`newTextFile'"  "$dataWorkFolder/Project_MasterDofile.do" , replace
}
end

	/***************************************************

		Here are all functions for combination of
		subcommand and item type

	***************************************************/

cap program drop 	iefolder_newProject
	program define	iefolder_newProject

		args projectfolder newHandle

		*Test if folder where to create new folder exist
		checkFolderExists "`projectfolder'" "parent"

		*Test that the new folder does not already exist
		checkFolderExists "$dataWorkFolder" "new"

		mkdir "$dataWorkFolder"

		******************************
		*Writing master do file header
		******************************

		*Write intro part with description of project,
		mdofle_p0 `newHandle' project

		*Write flolder globals section header and the root folders
		mdofle_p1 `newHandle' "`projectfolder'"

		*Write globals section header and the root folders
		mdofle_p2 `newHandle'

		*Write section that runs sub-master dofiles
		mdofle_p3 `newHandle' project

end

cap program drop 	iefolder_newRound
	program define	iefolder_newRound

	args subHandle rndName rndAbb

	di "new round command"

	*Test if folder where to create new folder exist
	checkFolderExists "$dataWorkFolder" "parent"

	*Test that the new folder does not already exist
	checkFolderExists "$dataWorkFolder/`rndName'" "new"

	*Old file reference
	tempname 	oldHandle
	local 		oldTextFile 	"$dataWorkFolder/Project_MasterDofile.do"

	file open `oldHandle' using `"`oldTextFile'"', read
	file read `oldHandle' line

	*Locals needed for the section devider
	local partNum 		= 0 //Keeps track of the part number

	while r(eof)==0 {

		*Do not interpret macros
		local line : subinstr local line "\$"  "\\$"
		local line : subinstr local line "\`"  "\\`"

		parseReadLine `"`line'"'

		if `r(ief_line)' == 0 {

			*This is a regular line of code. It should be copied as-is. No action needed.
			file write	`subHandle' `"`line'"' _n

		}
		else if `r(ief_line)' == 1 {

			**This is a line of code with a devisor written by
			* iefodler. New additions to a section are always added right before an end of section line.

			*return list

			**This is NOT an end of section line. Nothing will be written here
			* but we test that there is no confict with previous names
			if `r(ief_end)' == 0 {

					*Test if it is an end of globals section as we are writing a new
					if "`r(sectionName)'" == "monitor" {

					*Write devisor for this section
					writeDevisor 			`subHandle' 1 RoundGlobals rounds `rndName' `rndAbb'

					*Write the globals to the master do file and create the folders
					newRndFolderAndGlobals 	`rndName' `rndAbb' "dataWorkFolder" `subHandle'

					*Write an empty line before the end devisor
					file write		`subHandle' "" _n

				}
				else {

					*Test that the folder name about to be used is not already in use
					if "`r(itemName)'" == "`rndName'" {
						noi di as error "{phang}The new round name `rndName' is already in use. No new folders are creaetd and the master do-files has not been changed.{p_end}"
						error 507
					}

					*Test that the folder name about to be used is not already in use
					if "`r(itemAbb)'" == "`rndAbb'" {
						noi di as error "{phang}The new round abbreviation `rndAbb' is already in use. No new folders are creaetd and the master do-files has not been changed.{p_end}"
						error 507
					}

				}

				*Copy the line as is
				file write		`subHandle' `"`line'"' _n
			}

			**This is an end of section line. We will add the new content here
			* before writing the end of section line
			else if `r(ief_end)' == 1 {

				*Test if it is an end of globals section as we are writing a new
				if "`r(partName)'" == "End_RunDofiles" {

					*Write devisor for this section
					writeDevisor 			`subHandle' 3 RunDofiles `rndName' `rndAbb'

					*Write the
					file write  `subHandle' ///
						_col(4)"if (0) { //Change the 0 to 1 to run the `rndName' master dofile" _n ///
						_col(8) `"do ""' _char(36) `"`rndAbb'/`rndName'_MasterDofile.do" "' _n ///
						_col(4)"}" ///
						_n

					*Write an empty line before the end devisor
					file write		`subHandle' "" _n

				}

				*Write the end of section line
				file write		`subHandle' `"`line'"' _n
			}
		}

		*Read next file and repeat the while loop
		file read `oldHandle' line
	}

	*Close the old file.
	file close `oldHandle'

end

cap program drop 	iefolder_newMaster
	program define	iefolder_newMaster

	args subHandle obsName

	di "new master command"

	global mastData 		"$dataWorkFolder/MasterData"
	global mastDataIDKey 	"$encryptFolder/IDMasterKey"

	*********************************************
	*Test if folder can be created where expected
	*********************************************

	*Test if folder where to create new folder exist
	checkFolderExists "$mastDataIDKey" "parent"

	*Test that the new folder does not already exist
	checkFolderExists "$mastDataIDKey/`obsName'" "new"

	*Test if folder where to create new fodler exist
	checkFolderExists "$mastData" "parent"

	*Test that the new folder does not already exist
	checkFolderExists "$mastData/`obsName'" "new"

	*************
	*create folder in masterdata

	*Old file reference
	tempname 	oldHandle
	local 		oldTextFile 	"$dataWorkFolder/Project_MasterDofile.do"

	file open `oldHandle' using `"`oldTextFile'"', read
	file read `oldHandle' line

	*Locals needed for the section devider
	local partNum 		= 0 //Keeps track of the part number

	while r(eof)==0 {

		*Do not interpret macros
		local line : subinstr local line "\$"  "\\$"
		local line : subinstr local line "\`"  "\\`"

		parseReadLine `"`line'"'

		if `r(ief_line)' == 1 & `r(ief_line)' == 1 & `r(ief_end)' == 0  & "`r(sectionName)'" == "rawData" {

			*Create master data folder and add global to folder in master do file
			cap createFolderWriteGlobal "`obsName'"  "mastData"  	mastData_`obsName'	`subHandle'

			if _rc == 693 {

				*If that folder exist, problem
				noi di as error "{phang}could not create new folder, folder name might already exist "
				error _rc

			}
			else if _rc != 0 {

				*Unexpected error, run the exact command name again and throw the error to user
				createFolderWriteGlobal "`obsName'"  "mastData"  	mastData_`obsName'	`subHandle'
			}

			file write		`subHandle' `"`line'"' _n

		}
		else {

			*Copy the line as is
			file write		`subHandle' `"`line'"' _n

		}

		*Read next file and repeat the while loop
		file read `oldHandle' line
	}

	*Close the old file.
	file close `oldHandle'

	*Create master data subfolders
	createFolderWriteGlobal "MasterDataSets"  	"mastData_`obsName'"  masterDataSets
	createFolderWriteGlobal "Dofiles"  			"mastData_`obsName'"  mastDataDo

		*************
	*create folder in encrypred ID key master

	createFolderWriteGlobal "`obsName'"  		"mastDataIDKey"  			mastData_E_`obsName'
	createFolderWriteGlobal "Data"  			"mastData_E_`obsName'"  	mastData_E_data
	createFolderWriteGlobal "Sampling"  		"mastData_E_`obsName'"  	mastData_E_Samp
	createFolderWriteGlobal "Treatment"  		"mastData_E_`obsName'"  	mastData_E_Treat

end


Handle the one-class special case which I just wrote into the documentation.

(untested)

/* load the C extension */
ensurelib_aberrance svm // check for libsvm
program _svm, plugin    // load _svm.plugin, the wrapper for libsvm

program define svm_train, eclass
  version 13

  // these defaults were taken from svm-train.c
  // (except that we have shrinking off by default)
  #delimit ;
  syntax varlist (numeric)
         [if] [in]
         [,
           // strings cannot have default values
           // ints and reals *must*
           // (and yes the only other data types known to syntax are int and real, despite the stata datatypes being str, int, byte, float, double, ...)
           //
           // also be careful of the mixed-case shenanigans

           Type(string)

           Kernel(string)

           GAMMA(real 0) COEF0(real 0) DEGree(int 3)

            C(real 1) P(real 0.1) NU(real 0.5)

           // weights() --> char* weight_label[], double weight[nr_weight] // how should this work?
           // apparently syntax has a special 'weights' argument which is maybe meant just for this purpose
           // but how to pass it on?
           EPSilon(real 0.001)

           SHRINKing PROBability

           CACHE_size(int 100)

           // if specified, a column to generate to mark which rows were detected as SVs
           SV(string)
         ];
  #delimit cr
  // stash because we run syntax again below, which will smash these
  local cmd = "`0'"
  local _varlist = "`varlist'"
  local _if = "`if'"
  local _in = "`in'"
  gettoken depvar indepvars : _varlist

  /* fill in defaults for the string values */
  if("`type'"=="") {
    local type = "C_SVC"
  }

  if("`type'" == "C_SVC" | "`type'" == "NU_SVC" /* | "`type'" == "ONE_CLASS" ???? */) {
    // "ensure" type is categorical
    local T : type `depvar'
    if("`T'"=="float" | "`T'"=="double") {
      di as error "Warning: `depvar' is a `T', which is usually used for continuous variables."
      di as error "         SV classification will cast real numbers to integers before fitting." //<-- this is done by libsvm with no control from us
      di as error
      di as error "         If your outcome is actually categorical, consider storing it as one:"
      di as error "         . tempvar B"
      di as error "         . generate byte \`B' = `depvar'"   //CAREFUL: B is meant to be quoted and depvar is meant to be unquoted.
      di as error "         . drop `depvar'"
      di as error "         . rename \`B' `depvar'"
      di as error "         (If your category encoding uses floating point levels this will not be enough)"
      di as error
      di as error "         Alternately, consider SV regression: type(EPSILON_SVR) or type(NU_SVR)."
      di as error
    }
  }

  if("`type'" == "ONE_CLASS") {
    // handle the special-case that one-class is unsupervised and so takes no
    //  libsvm still reads a Y vector though; it just, apparently, ignores it
    //  rather than tweaking numbers to be off-by-one, the easiest is to silently
    //  duplicate the pointer to one of the variables.
    gettoken Y : varlist
    local varlist = "`Y' `varlist'"
  }

  if("`kernel'"=="") {
    local kernel = "RBF"
  }

  /* make the string variables case insensitive (by forcing them to CAPS and letting the .c deal with them that way) */
  local type = upper("`type'")
  local kernel = upper("`kernel'")

  /* translate the boolean flags into integers */
  // the protocol here is silly, because syntax special-cases "no" prefixes:
  // *if* the user gives the no form of the option, a macro is defined with "noprobability" in lower case in it
  // in all *other* cases, the macro is undefined (so if you eval it you get "")
  // conversely, with regular option flags, if the user gives it you get a macro with "shrinking" in it, and otherwise the macro is undefined

  if("`shrinking"=="shrinking") {
    local shrinking = 1
  }
  else {
    local shrinking = 0
  }

  if("`probability'"=="probability") {
    local probability = 1

    // ensure model is a classification
    if("`type'" != "C_SVC" & "`type'" != "NU_SVC") {
      // the command line tools *allow* this combination, but at prediction time silently change the parameters
      // "Errors should never pass silently. Unless explicitly silenced." -- Tim Peters, The Zen of Python
      di as error "Error: requested model is a `type'. You can only use the probability option with classification models (C_SVC, NU_SVC)."
      exit 2
    }
  }
  else {
    local probability = 0
  }

  // fail-fast on name errors in sv()
  if("`sv'"!="") {
    local 0 = "`sv'"
    syntax newvarname

  }

  /* call down into C */
  #delimit ;
  plugin call _svm `_varlist' `_if' `_in', "train"
      "`type'" "`kernel'"
      "`gamma'" "`coef0'" "`degree'"
      "`c'" "`p'" "`nu'"
      "`epsilon'"
      "`shrinking'" "`probability'"
      "`cache_size'"
      ;
  #delimit cr

  /* fixup the e() dictionary */
  ereturn clear

  // set standard Stata estimation (e()) properties
  ereturn local cmd = "svm_train"
  ereturn local cmdline = "`e(cmd)' `cmd'"
  ereturn local predict = "svm_predict" //this is a function pointer, or as close as Stata has to that: causes "predict" to run "svm_predict"
  ereturn local estat = "svm_estat"     //ditto. NOT IMPLEMENTED

  ereturn local title = "Support Vector Machine"
  ereturn local model = "svm"
  ereturn local svm_type = "`type'"
  ereturn local svm_kernel = "`kernel'"

  ereturn local depvar = "`depvar'"
  //ereturn local indepvars = "`indepvars'" //XXX Instead svm_predict reparses cmdline. This needs vetting.

  // append the svm_model structure to e()
  _svm_model2stata `_if' `_in', sv(`sv')
end

/* load the C extension */
ensurelib_aberrance svm // check for libsvm
program _svm, plugin    // load _svm.plugin, the wrapper for libsvm

program define svm_train, eclass
  version 13

  // these defaults were taken from svm-train.c
  // (except that we have shrinking off by default)
  #delimit ;
  syntax varlist (numeric)
         [if] [in]
         [,
           // strings cannot have default values
           // ints and reals *must*
           // (and yes the only other data types known to syntax are int and real, despite the stata datatypes being str, int, byte, float, double, ...)
           //
           // also be careful of the mixed-case shenanigans

           Type(string)

           Kernel(string)

           GAMMA(real 0) COEF0(real 0) DEGree(int 3)

            C(real 1) P(real 0.1) NU(real 0.5)

           // weights() --> char* weight_label[], double weight[nr_weight] // how should this work?
           // apparently syntax has a special 'weights' argument which is maybe meant just for this purpose
           // but how to pass it on?
           EPSilon(real 0.001)

           SHRINKing PROBability

           CACHE_size(int 100)

           // if specified, a column to generate to mark which rows were detected as SVs
           SV(string)
         ];
  #delimit cr
  // stash because we run syntax again below, which will smash these
  local cmd = "`0'"
  local _varlist = "`varlist'"
  local _if = "`if'"
  local _in = "`in'"
  gettoken depvar indepvars : _varlist

  /* fill in defaults for the string values */
  if("`type'"=="") {
    local type = "C_SVC"
  }

  if("`type'" == "C_SVC" | "`type'" == "NU_SVC" /* | "`type'" == "ONE_CLASS" ???? */) {
    // "ensure" type is categorical
    local T : type `depvar'
    if("`T'"=="float" | "`T'"=="double") {
      di as error "Warning: `depvar' is a `T', which is usually used for continuous variables."
      di as error "         SV classification will cast real numbers to integers before fitting." //<-- this is done by libsvm with no control from us
      di as error
      di as error "         If your outcome is actually categorical, consider storing it as one:"
      di as error "         . tempvar B"
      di as error "         . generate byte \`B' = `depvar'"   //CAREFUL: B is meant to be quoted and depvar is meant to be unquoted.
      di as error "         . drop `depvar'"
      di as error "         . rename \`B' `depvar'"
      di as error "         (If your category encoding uses floating point levels this will not be enough)"
      di as error
      di as error "         Alternately, consider SV regression: type(EPSILON_SVR) or type(NU_SVR)."
      di as error
    }
  }

  if("`kernel'"=="") {
    local kernel = "RBF"
  }

  /* make the string variables case insensitive (by forcing them to CAPS and letting the .c deal with them that way) */
  local type = upper("`type'")
  local kernel = upper("`kernel'")

  /* translate the boolean flags into integers */
  // the protocol here is silly, because syntax special-cases "no" prefixes:
  // *if* the user gives the no form of the option, a macro is defined with "noprobability" in lower case in it
  // in all *other* cases, the macro is undefined (so if you eval it you get "")
  // conversely, with regular option flags, if the user gives it you get a macro with "shrinking" in it, and otherwise the macro is undefined

  if("`shrinking"=="shrinking") {
    local shrinking = 1
  }
  else {
    local shrinking = 0
  }

  if("`probability'"=="probability") {
    local probability = 1

    // ensure model is a classification
    if("`type'" != "C_SVC" & "`type'" != "NU_SVC") {
      // the command line tools *allow* this combination, but at prediction time silently change the parameters
      // "Errors should never pass silently. Unless explicitly silenced." -- Tim Peters, The Zen of Python
      di as error "Error: requested model is a `type'. You can only use the probability option with classification models (C_SVC, NU_SVC)."
      exit 2
    }
  }
  else {
    local probability = 0
  }

  // fail-fast on name errors in sv()
  if("`sv'"!="") {
    local 0 = "`sv'"
    syntax newvarname

  }

  /* call down into C */
  #delimit ;
  plugin call _svm `_varlist' `_if' `_in', "train"
      "`type'" "`kernel'"
      "`gamma'" "`coef0'" "`degree'"
      "`c'" "`p'" "`nu'"
      "`epsilon'"
      "`shrinking'" "`probability'"
      "`cache_size'"
      ;
  #delimit cr

  /* fixup the e() dictionary */
  ereturn clear

  // set standard Stata estimation (e()) properties
  ereturn local cmd = "svm_train"
  ereturn local cmdline = "`e(cmd)' `cmd'"
  ereturn local predict = "svm_predict" //this is a function pointer, or as close as Stata has to that: causes "predict" to run "svm_predict"
  ereturn local estat = "svm_estat"     //ditto. NOT IMPLEMENTED

  ereturn local title = "Support Vector Machine"
  ereturn local model = "svm"
  ereturn local svm_type = "`type'"
  ereturn local svm_kernel = "`kernel'"

  ereturn local depvar = "`depvar'"
  //ereturn local indepvars = "`indepvars'" //XXX Instead svm_predict reparses cmdline. This needs vetting.

  // append the svm_model structure to e()
  _svm_model2stata `_if' `_in', sv(`sv')
end