Add wave setup, use self-compiled hello rom.

# Xilinx WebPack modelsim script
#
# cd C:/workspace/zpu/zpu/hdl/example_medium
# do simzpu_medium.do

set BreakOnAssertion 1
vlib zpu

#vcom -work zpu ../vhdl/roms/hello_bram.vhdl
#vcom -work zpu ../vhdl/roms/my_hello.vhdl
vcom -work zpu ../vhdl/roms/hello.vhdl
#vcom -work zpu ../vhdl/roms/hello_dbram.vhdl
vcom -work zpu ../vhdl/roms/rom_pkg.vhdl

vcom -work zpu ../vhdl/zpu_pkg.vhdl
#vcom -work zpu ../vhdl/zpu_small.vhdl
vcom -work zpu ../vhdl/zpu_medium.vhdl

vcom -work zpu ../vhdl/helpers/zpu_med1.vhdl
#vcom -work zpu ../vhdl/helpers/zpu_small1.vhdl

vcom -work zpu  ../vhdl/devices/txt_util.vhdl
vcom -work zpu  ../vhdl/devices/phi_io.vhdl
vcom -work zpu  ../vhdl/devices/timer.vhdl
vcom -work zpu  ../vhdl/devices/gpio.vhdl
vcom -work zpu  ../vhdl/devices/rx_unit.vhdl
vcom -work zpu  ../vhdl/devices/tx_unit.vhdl
vcom -work zpu  ../vhdl/devices/br_gen.vhdl
vcom -work zpu  ../vhdl/devices/trace.vhdl

vlib work
vcom -work work ../vhdl/roms/rom_pkg.vhdl
vcom -work work ../vhdl/testbenches/dmips_med1_tb.vhdl

# run ZPU
vsim DMIPS_Med1_TB

view wave

onerror {resume}
quietly WaveActivateNextPane {} 0
add wave -noupdate -group TB /dmips_med1_tb/clk
add wave -noupdate -group TB /dmips_med1_tb/reset
add wave -noupdate -group TB /dmips_med1_tb/interrupt
add wave -noupdate -group TB /dmips_med1_tb/break
add wave -noupdate -group TB /dmips_med1_tb/dbg
add wave -noupdate -group TB /dmips_med1_tb/rs232_tx
add wave -noupdate -group TB /dmips_med1_tb/rs232_rx
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/clk_i
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/rst_i
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/interrupt_i
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/break_o
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/dbg_o
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/rs232_tx_o
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/rs232_rx_i
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/gpio_in
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/gpio_out
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/gpio_dir
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/mem_busy
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/mem_read
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/mem_write
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/mem_addr
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/mem_we
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/mem_re
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/ram_busy
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/ram_read
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/ram_addr
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/ram_we
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/ram_re
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/ram_ready_r
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/io_busy
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/io_re
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/io_we
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/io_read
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/io_ready
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/io_reading_r
add wave -noupdate -group {ZPU port} /dmips_med1_tb/zpu/io_addr
add wave -noupdate -group Memory /dmips_med1_tb/zpu/memory/clk_i
add wave -noupdate -group Memory /dmips_med1_tb/zpu/memory/we_i
add wave -noupdate -group Memory /dmips_med1_tb/zpu/memory/re_i
add wave -noupdate -group Memory /dmips_med1_tb/zpu/memory/addr_i
add wave -noupdate -group Memory /dmips_med1_tb/zpu/memory/write_i
add wave -noupdate -group Memory /dmips_med1_tb/zpu/memory/read_o
add wave -noupdate -group Memory /dmips_med1_tb/zpu/memory/busy_o
add wave -noupdate -group Memory /dmips_med1_tb/zpu/memory/addr_r
add wave -noupdate -group Memory /dmips_med1_tb/zpu/memory/ram
add wave -noupdate -group IO -group Control /dmips_med1_tb/zpu/io_map/clk_i
add wave -noupdate -group IO -group Control /dmips_med1_tb/zpu/io_map/reset_i
add wave -noupdate -group IO -group Control /dmips_med1_tb/zpu/io_map/busy_o
add wave -noupdate -group IO -group Control /dmips_med1_tb/zpu/io_map/we_i
add wave -noupdate -group IO -group Control /dmips_med1_tb/zpu/io_map/re_i
add wave -noupdate -group IO -group Control /dmips_med1_tb/zpu/io_map/data_i
add wave -noupdate -group IO -group Control /dmips_med1_tb/zpu/io_map/data_o
add wave -noupdate -group IO -group Control /dmips_med1_tb/zpu/io_map/addr_i
add wave -noupdate -group IO -group UART /dmips_med1_tb/zpu/io_map/rs232_rx_i
add wave -noupdate -group IO -group UART /dmips_med1_tb/zpu/io_map/rs232_tx_o
add wave -noupdate -group IO -group UART /dmips_med1_tb/zpu/io_map/br_clk_i
add wave -noupdate -group IO -group UART /dmips_med1_tb/zpu/io_map/rx_br
add wave -noupdate -group IO -group UART /dmips_med1_tb/zpu/io_map/uart_read
add wave -noupdate -group IO -group UART /dmips_med1_tb/zpu/io_map/rx_avail
add wave -noupdate -group IO -group UART /dmips_med1_tb/zpu/io_map/rx_data
add wave -noupdate -group IO -group UART /dmips_med1_tb/zpu/io_map/tx_br
add wave -noupdate -group IO -group UART /dmips_med1_tb/zpu/io_map/uart_write
add wave -noupdate -group IO -group UART /dmips_med1_tb/zpu/io_map/tx_busy
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/rx_core/clk_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/rx_core/reset_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/rx_core/enable_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/rx_core/read_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/rx_core/rxd_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/rx_core/rxav_o
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/rx_core/datao_o
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/rx_core/r_r
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/rx_core/bavail_r
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/tx_core/clk_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/tx_core/reset_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/tx_core/enable_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/tx_core/load_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/tx_core/txd_o
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/tx_core/busy_o
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/tx_core/datai_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/tx_core/tbuff_r
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/tx_core/t_r
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/tx_core/loaded_r
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/tx_core/txd_r
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/rx_timer/clk_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/rx_timer/reset_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/rx_timer/ce_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/rx_timer/o_o
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/tx_timer/clk_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/tx_timer/reset_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/tx_timer/ce_i
add wave -noupdate -group IO -group {UART tx/rx} /dmips_med1_tb/zpu/io_map/tx_timer/o_o
add wave -noupdate -group IO -group timer /dmips_med1_tb/zpu/io_map/is_timer
add wave -noupdate -group IO -group timer /dmips_med1_tb/zpu/io_map/timerinst/clk_i
add wave -noupdate -group IO -group timer /dmips_med1_tb/zpu/io_map/timerinst/reset_i
add wave -noupdate -group IO -group timer /dmips_med1_tb/zpu/io_map/timerinst/we_i
add wave -noupdate -group IO -group timer -radix hexadecimal /dmips_med1_tb/zpu/io_map/timer_read
add wave -noupdate -group IO -group timer /dmips_med1_tb/zpu/io_map/timer_we
add wave -noupdate -group IO -group timer -radix hexadecimal /dmips_med1_tb/zpu/io_map/timerinst/data_i
add wave -noupdate -group IO -group timer /dmips_med1_tb/zpu/io_map/timerinst/addr_i
add wave -noupdate -group IO -group timer -radix hexadecimal /dmips_med1_tb/zpu/io_map/timerinst/data_o
add wave -noupdate -group IO -group timer /dmips_med1_tb/zpu/io_map/timerinst/sample
add wave -noupdate -group IO -group timer /dmips_med1_tb/zpu/io_map/timerinst/reset
add wave -noupdate -group IO -group timer -radix hexadecimal /dmips_med1_tb/zpu/io_map/timerinst/cnt
add wave -noupdate -group IO -group timer -radix hexadecimal /dmips_med1_tb/zpu/io_map/timerinst/cnt_smp
add wave -noupdate -group GPIO /dmips_med1_tb/zpu/io_map/gpio_we
add wave -noupdate -group GPIO /dmips_med1_tb/zpu/io_map/is_gpio
add wave -noupdate -group GPIO /dmips_med1_tb/zpu/io_map/gpio_read
add wave -noupdate -group GPIO -radix hexadecimal /dmips_med1_tb/zpu/io_map/gpio_in
add wave -noupdate -group GPIO -radix hexadecimal /dmips_med1_tb/zpu/io_map/gpio_out
add wave -noupdate -group GPIO -radix hexadecimal /dmips_med1_tb/zpu/io_map/gpio_dir
add wave -noupdate -group GPIO /dmips_med1_tb/zpu/io_map/gpio_i0/clk_i
add wave -noupdate -group GPIO /dmips_med1_tb/zpu/io_map/gpio_i0/reset_i
add wave -noupdate -group GPIO /dmips_med1_tb/zpu/io_map/gpio_i0/we_i
add wave -noupdate -group GPIO -radix hexadecimal /dmips_med1_tb/zpu/io_map/gpio_i0/data_i
add wave -noupdate -group GPIO /dmips_med1_tb/zpu/io_map/gpio_i0/addr_i
add wave -noupdate -group GPIO -radix hexadecimal /dmips_med1_tb/zpu/io_map/gpio_i0/data_o
add wave -noupdate -group GPIO -radix hexadecimal /dmips_med1_tb/zpu/io_map/gpio_i0/port_in
add wave -noupdate -group GPIO -radix hexadecimal /dmips_med1_tb/zpu/io_map/gpio_i0/port_out
add wave -noupdate -group GPIO -radix hexadecimal /dmips_med1_tb/zpu/io_map/gpio_i0/port_dir
add wave -noupdate -group GPIO -radix hexadecimal /dmips_med1_tb/zpu/io_map/gpio_i0/port_in_reg
add wave -noupdate -group GPIO -radix hexadecimal /dmips_med1_tb/zpu/io_map/gpio_i0/port_in_sync
add wave -noupdate -group GPIO -radix hexadecimal /dmips_med1_tb/zpu/io_map/gpio_i0/direction
add wave -noupdate -expand -group {ZPU control} /dmips_med1_tb/zpu/zpu/clk_i
add wave -noupdate -expand -group {ZPU control} /dmips_med1_tb/zpu/zpu/reset_i
add wave -noupdate -expand -group {ZPU control} /dmips_med1_tb/zpu/zpu/interrupt_i
add wave -noupdate -expand -group {ZPU control} /dmips_med1_tb/zpu/zpu/enable_i
add wave -noupdate -expand -group {ZPU control} /dmips_med1_tb/zpu/zpu/break_o
add wave -noupdate -expand -group {ZPU control} /dmips_med1_tb/zpu/zpu/in_irq_r
add wave -noupdate -expand -group {ZPU control} /dmips_med1_tb/zpu/zpu/idim_r
add wave -noupdate -expand -group {ZPU registers} -radix hexadecimal /dmips_med1_tb/zpu/zpu/pc_r
add wave -noupdate -expand -group {ZPU registers} -radix hexadecimal /dmips_med1_tb/zpu/zpu/sp_r
add wave -noupdate -expand -group {ZPU registers} -radix hexadecimal /dmips_med1_tb/zpu/zpu/inc_sp
add wave -noupdate -expand -group {ZPU registers} -radix hexadecimal /dmips_med1_tb/zpu/zpu/inc_inc_sp
add wave -noupdate -expand -group {ZPU registers} -radix hexadecimal /dmips_med1_tb/zpu/zpu/a_r
add wave -noupdate -expand -group {ZPU registers} -radix hexadecimal /dmips_med1_tb/zpu/zpu/b_r
add wave -noupdate -expand -group {ZPU registers} -radix hexadecimal /dmips_med1_tb/zpu/zpu/fetched_w_r
add wave -noupdate -expand -group {ZPU registers} /dmips_med1_tb/zpu/zpu/state
add wave -noupdate -expand -group {ZPU registers} /dmips_med1_tb/zpu/zpu/insn
add wave -noupdate -expand -group {ZPU registers} /dmips_med1_tb/zpu/zpu/insns
add wave -noupdate -expand -group {ZPU registers} -radix hexadecimal /dmips_med1_tb/zpu/zpu/opcode_r
add wave -noupdate -expand -group {ZPU Memory} /dmips_med1_tb/zpu/zpu/mem_busy_i
add wave -noupdate -expand -group {ZPU Memory} /dmips_med1_tb/zpu/zpu/write_en_r
add wave -noupdate -expand -group {ZPU Memory} /dmips_med1_tb/zpu/zpu/read_en_r
add wave -noupdate -expand -group {ZPU Memory} -radix hexadecimal /dmips_med1_tb/zpu/zpu/addr_r
add wave -noupdate -expand -group {ZPU Memory} -radix hexadecimal /dmips_med1_tb/zpu/zpu/data_i
add wave -noupdate -expand -group {ZPU Memory} -radix hexadecimal /dmips_med1_tb/zpu/zpu/data_o
add wave -noupdate -expand -group {ZPU Memory} -radix hexadecimal /dmips_med1_tb/zpu/zpu/addr_o
add wave -noupdate -expand -group {ZPU Memory} /dmips_med1_tb/zpu/zpu/write_en_o
add wave -noupdate -expand -group {ZPU Memory} /dmips_med1_tb/zpu/zpu/read_en_o
add wave -noupdate -group {ZPU mul} -radix hexadecimal /dmips_med1_tb/zpu/zpu/bin_op_res1_r
add wave -noupdate -group {ZPU mul} -radix hexadecimal /dmips_med1_tb/zpu/zpu/bin_op_res2_r
add wave -noupdate -group {ZPU mul} -radix hexadecimal /dmips_med1_tb/zpu/zpu/mult_res1_r
add wave -noupdate -group {ZPU mul} -radix hexadecimal /dmips_med1_tb/zpu/zpu/mult_res2_r
add wave -noupdate -group {ZPU mul} -radix hexadecimal /dmips_med1_tb/zpu/zpu/mult_res3_r
add wave -noupdate -group {ZPU mul} -radix hexadecimal /dmips_med1_tb/zpu/zpu/mult_a_r
add wave -noupdate -group {ZPU mul} -radix hexadecimal /dmips_med1_tb/zpu/zpu/mult_b_r
add wave -noupdate /dmips_med1_tb/zpu/zpu/dbg_o
add wave -noupdate /dmips_med1_tb/trace_mod/clk_i
add wave -noupdate /dmips_med1_tb/trace_mod/dbg_i
add wave -noupdate /dmips_med1_tb/trace_mod/stop_i
add wave -noupdate /dmips_med1_tb/trace_mod/busy_i
add wave -noupdate /dmips_med1_tb/trace_mod/counter
TreeUpdate [SetDefaultTree]
WaveRestoreCursors {{Cursor 1} {1835128 ps} 0}
quietly wave cursor active 1
configure wave -namecolwidth 340
configure wave -valuecolwidth 100
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 ps
update
WaveRestoreZoom {1701840 ps} {1957632 ps}

#add wave -recursive *
view structure
#view signals

# Enough to run tiny programs
run 10000 ms

# Xilinx WebPack modelsim script
#
# cd C:/workspace/zpu/zpu/hdl/example_medium
# do simzpu_medium.do

set BreakOnAssertion 1
vlib zpu

vcom -work zpu ../vhdl/roms/hello_bram.vhdl
#vcom -work zpu ../vhdl/roms/hello_dbram.vhdl
vcom -work zpu ../vhdl/roms/rom_pkg.vhdl

vcom -work zpu ../vhdl/zpu_pkg.vhdl
#vcom -work zpu ../vhdl/zpu_small.vhdl
vcom -work zpu ../vhdl/zpu_medium.vhdl

vcom -work zpu ../vhdl/helpers/zpu_med1.vhdl
#vcom -work zpu ../vhdl/helpers/zpu_small1.vhdl

vcom -work zpu  ../vhdl/devices/txt_util.vhdl
vcom -work zpu  ../vhdl/devices/phi_io.vhdl
vcom -work zpu  ../vhdl/devices/timer.vhdl
vcom -work zpu  ../vhdl/devices/gpio.vhdl
vcom -work zpu  ../vhdl/devices/rx_unit.vhdl
vcom -work zpu  ../vhdl/devices/tx_unit.vhdl
vcom -work zpu  ../vhdl/devices/br_gen.vhdl
vcom -work zpu  ../vhdl/devices/trace.vhdl

vlib work
vcom -work work ../vhdl/roms/rom_pkg.vhdl
vcom -work work ../vhdl/testbenches/dmips_med1_tb.vhdl

# run ZPU
vsim DMIPS_Med1_TB
view wave
add wave -recursive *
view structure
#view signals

# Enough to run tiny programs
run 10000 ms


[iegitaddmd ?] explicit that subfolders are also skipped

{smcl}
{* 5 Nov 2019}{...}
{hline}
help for {hi:iegitaddmd}
{hline}

{title:Title}

{cmd:iegitaddmd} {hline 2} Creates a placeholder file in subfolders of a GitHub repository folder, which allows committing folder structures with empty folders.

{phang2}For a more descriptive discussion on the intended usage and work flow of this
command please see the {browse "https://dimewiki.worldbank.org/wiki/Iegitaddmd":DIME Wiki}.

{title:Syntax}

{phang} {cmdab:iegitaddmd} , {opt folder(full_file_path)} [{opt comparefolder(full_file_path)} {cmd:customfile(}{it:{help filename}}{cmd:)} {opt all} {opt skip} {opt replace} {opt skipfolders(folder_name)}  {opt auto:matic} {opt dry:run}]

{marker opts}{...}
{synoptset 28}{...}
{synopthdr:options}
{synoptline}
{synopt :{opt folder(full_file_path)}}Specifies the folder path to the project folder clone where placeholder files will be created{p_end}
{synopt :{opt comparefolder(full_file_path)}}Specifies the top folder of a folder tree to be compared with {opt folder()}{p_end}
{synopt :{cmd:customfile(}{it:{help filename}}{cmd:)}}Specifies a file saved on disk that is used instead of the default file as placeholder{p_end}
{synopt :{cmd:all}}Creates the placeholder file in every subfolder of {opt folder()}, whether empty or not{p_end}
{synopt :{opt skip}}If option {opt all} is used and a folder has a file with same name as placeholder file, then nothing is done{p_end}
{synopt :{opt replace}}If option {opt all} is used and a folder has a file with same name as placeholder file, then the file is overwritten{p_end}
{synopt :{opt skipfolders(folder_name)}}List of folders to be skipped. The folder {it:.git} is always added to this list, even when option is not used{p_end}
{synopt :{opt auto:matic}}Makes the command create placeholder files without prompting the user for each file{p_end}
{synopt :{opt dry:run}}Makes the command list all the files that would have been created without this option.{p_end}
{synoptline}

{marker desc}
{title:Description}

{pstd}GitHub does not sync empty folders, or folder that only contain ignored files. However, it is common in research projects that these types of folders needs to be shared anyways. {cmd:iegitaddmd} provides a solution to this by creating placeholder files in in these folders. This placeholder file can then be shared to GitHub and that way the folder is also shared. {cmd:iegitaddmd} have two ways to identify which those folders are that are developed with the two use cases described below in mind.{p_end}

{pstd}{bf:Use case 1.} It is common in the beginning of a research project that a standardized folder structure is set up (for example with {help iefolder}) where some folders are created that are not yet needed. Examples of folders like that could be the output folders. If these folders are not shared at the time they are created, there is a risk that different team members name them differently which will be confusing and could lead to errors. {cmd:iegitaddmd} can solve this by scanning a folder and all its sub-folders for completely empty folders, and create a placeholder file in that folder.{p_end}

{pstd}The solution to use case 1 in {cmd:iegitaddmd} is a Stata adaptation of {it:Solution B} in {browse "http://bytefreaks.net/gnulinux/bash/how-to-add-automatically-all-empty-folders-in-git-repository" :this post}.{p_end}

{pstd}{bf:Use case 2.} A common method when transferring an already ongoing research project to GitHub is to copy all of the data work folder from wherever the files and folders where shared before (for example DropBox) to a clone of the repository. Then only the files that are meant to be shared on GitHub are uploaded to the cloud using a {it:.gitignore file}. Empty folders or folders where all files are ignored is then not shared through GitHub. {cmd:iegitaddmd} can solve this by scanning the DropBox folder (or wherever the project folder was shared before) for sub-folders that exist in that folder but not in the clone and crate that folder in the clone and put a placeholder in it.{p_end}

{pstd}The way you differentiate between these two use cases when using {cmd:iegitaddmd} is whether the option {opt comparefolder()} is used or not. If that option is used, then {cmd:iegitaddmd} will identify all folders that are in {opt comparefolder()} that is not in {opt folder()}, and create a placeholder file there. If {opt comparefolder()} is not used, then {cmd:iegitaddmd} will identify all completely empty folders (no files or subfolders) and create a placeholder file there.{p_end}

{pstd}The default placeholder file used if no file is specified using option {opt customfile()} is called README.md, which is a name and format recognized by GitHub.com so that the content of the file is displayed on GitHub.com when navigating to that folder using a browser. The placeholder file may be removed as	soon as files that are not ignored have been added to the folder, or even better is to keep the file but edit the content of it so it documents the content of that folder for other and future team members.{p_end}

{marker optslong}
{title:Options}

{phang}{opt folder(file_path)} is the folder path to the project folder clone where the placeholder files will be created. Unless option {opt comparefolder()} or {opt all} is used, then placeholder files will be created in all empty folders. See option {opt manual} for a way to manually confirm each folder before a placeholder file is created in it.{p_end}

{phang}{opt comparefolder(file_path)} is used to compare a file tree in a different location and create the folders with placeholder files in all folders that exist in {opt comparefolder()} but not in {opt folder()}. If a folder that does no exist in {opt folder()} has a subfolder, then both the folder and the subfolder will be created and the placeholder file is only crated in the sub-folder. This is enough to share both folder and the subfolder in GitHub. If the {opt comparefolder()} and {opt folder()} ends with folders with different names, for example {opt folder(${project}/datawork/baseline)} and {opt comparefolder(${project}/datawork)}, then the command will throw an error as it is likely that the paths do not point to corresponding folders in the two folder trees. See option {opt manual} for a way to manually confirm each folder before a placeholder file is created in it.{p_end}

{phang}{cmd:file(}{it:{help filename}}{cmd:)} allows the user to specify a file saved on
	the computer to be used as the placeholder file	instead of the default README.md file. This
	allows people and organizations to write their own template placeholder files according to their own
	preferences. We recommend that a file of type .md (markdown) and name README.md is used as
	GitHub.com recognizes this name and format and will display the content of the file when someone
	browse to that folder on GitHub.com. But this is not a technical requirement, any file type
	and name can be used as placeholder file.{p_end}

{phang}{opt all} creates the placeholder file in {opt folder()} and in every subfolder,
	regardless if they are empty or not. This allows the user to create a placeholder file in every
	folder that can be edited with documentation and instructions to the purpose and usage of
	each subfolder. This option can also be important when .{it:gitignore} is used, as {cmd:iegitaddmd} will not
	create files to subfolders that only has ignored file -- in which case the folder will not
	be synced by GitHub.{p_end}

{phang}{opt skip} and {opt replace} tells {cmd:iegitaddmd} what to do if the option {opt all} is used
	and if any of the folders contain a file with the same name as the placeholder file the command
	is trying to create. If a file with the same name as the placeholder file exist and neither of these options
	are used, then the command will throw an error. If {opt skip} is used, then nothing is done in the
	folder where the file with the same name exists and the command proceeds to the next folder.
	If {opt replace} is used then the file with the same name is overwritten with the new placeholder
	file before the command proceeds to the next folder.{p_end}

{phang}{opt skipfolders(folder_name)} can be used to tell {cmd:iegitaddmd} which folders
in which a placeholder file should never be created. The best example of this is the {it:.git}
folder in which placeholders never should be created. That name is always skipped regardless of
this option being used or not. Use this option to list additional folders to be skipped. You
should not list the full folder path in this option, just the folder name. All folders with
that name will be skipped regardless of their location in the project folder.
Any sub-folder of these folders will also be skipped. The folder names may
be listed with or without quotation marks as long as there are no spaces in the names. If any of
the folder names has spaces, then quotation marks must be used for all folder names.

{phang}{opt auto:matic} can be used to speed up the creation of placeholders by telling the
command to not prompt the users for confirmation for each file before it is created. The
default is that the command is asking the user before creating each place holder file.
This option should only be used when you are confident you have specified the correct folder
paths. We recommend that you use the {opt dryrun} with this option to make sure that the
folder paths are correct.{p_end}

{phang}{opt dry:run} can be used to safely test that the folder paths are specified correctly
before any placeholder files are created. When this option it used the command simply lists
the file that would have been created if this option were not used. Once you are confident
that list is correct, you can remove this option and re-run the command and the files will
be created.{p_end}

{title:Example}

{pstd}{inp:global github_folder "C:\Users\JohnSmith\Documents\GitHub\ProjectA"}{break}{inp:iegitaddmd , folder({it:"$github_folder"})}{p_end}

{pstd}In the example above, there is a GitHub repository in the folder ProjectA. This
	repository has a folder structure where some folders are still empty but will later
	be populated with files. In order to have all folders, even the empty ones, synced on all
	collaborators' cloned local copies of the repository, the folders need to contain at least
	one file, which is being created by the command.{p_end}

{pstd}{inp:global github_folder "C:\Users\JohnSmith\Documents\GitHub\ProjectB"}{break}{inp:iegitaddmd , folder({it:"$github_folder"}) skipfolders("foo" "bar")}{p_end}

{pstd}In the example above, there is a GitHub repository in the folder ProjectB. This
is a project similar to ProjectA above but it has to folder, called {inp:foo} and {inp:bar}
in which no placeholder files should ever be created in. Any subfolders in {inp:foo}
or {inp:bar} will be skipped as well. The folder {inp:.git} is a system folder in git
repositories and will always be skipped.{p_end}

{title:Author}

{phang}All commands in ietoolkit is developed by DIME Analytics at DECIE, The World Bank's unit for Development Impact Evaluations.

{phang}Author: DIME Analytics, The World Bank Group

{phang}Please send bug-reports, suggestions and requests for clarifications
		 writing "ietoolkit iegitaddmd" in the subject line to:{break}
		 dimeanalytics@worldbank.org

{phang}You can also see the code, make comments to the code, see the version
		 history of the code, and submit additions or edits to the code through {browse "https://github.com/worldbank/ietoolkit":the GitHub repository of ietoolkit}.{p_end}

{smcl}
{* 5 Nov 2019}{...}
{hline}
help for {hi:iegitaddmd}
{hline}

{title:Title}

{cmd:iegitaddmd} {hline 2} Creates a placeholder file in subfolders of a GitHub repository folder, which allows committing folder structures with empty folders.

{phang2}For a more descriptive discussion on the intended usage and work flow of this
command please see the {browse "https://dimewiki.worldbank.org/wiki/Iegitaddmd":DIME Wiki}.

{title:Syntax}

{phang} {cmdab:iegitaddmd} , {opt folder(full_file_path)} [{opt comparefolder(full_file_path)} {cmd:customfile(}{it:{help filename}}{cmd:)} {opt all} {opt skip} {opt replace} {opt skipfolders(folder_name)}  {opt auto:matic} {opt dry:run}]

{marker opts}{...}
{synoptset 28}{...}
{synopthdr:options}
{synoptline}
{synopt :{opt folder(full_file_path)}}Specifies the folder path to the project folder clone where placeholder files will be created{p_end}
{synopt :{opt comparefolder(full_file_path)}}Specifies the top folder of a folder tree to be compared with {opt folder()}{p_end}
{synopt :{cmd:customfile(}{it:{help filename}}{cmd:)}}Specifies a file saved on disk that is used instead of the default file as placeholder{p_end}
{synopt :{cmd:all}}Creates the placeholder file in every subfolder of {opt folder()}, whether empty or not{p_end}
{synopt :{opt skip}}If option {opt all} is used and a folder has a file with same name as placeholder file, then nothing is done{p_end}
{synopt :{opt replace}}If option {opt all} is used and a folder has a file with same name as placeholder file, then the file is overwritten{p_end}
{synopt :{opt skipfolders(folder_name)}}List of folders to be skipped. The folder {it:.git} is always added to this list, even when option is not used{p_end}
{synopt :{opt auto:matic}}Makes the command create placeholder files without prompting the user for each file{p_end}
{synopt :{opt dry:run}}Makes the command list all the files that would have been created without this option.{p_end}
{synoptline}

{marker desc}
{title:Description}

{pstd}GitHub does not sync empty folders, or folder that only contain ignored files. However, it is common in research projects that these types of folders needs to be shared anyways. {cmd:iegitaddmd} provides a solution to this by creating placeholder files in in these folders. This placeholder file can then be shared to GitHub and that way the folder is also shared. {cmd:iegitaddmd} have two ways to identify which those folders are that are developed with the two use cases described below in mind.{p_end}

{pstd}{bf:Use case 1.} It is common in the beginning of a research project that a standardized folder structure is set up (for example with {help iefolder}) where some folders are created that are not yet needed. Examples of folders like that could be the output folders. If these folders are not shared at the time they are created, there is a risk that different team members name them differently which will be confusing and could lead to errors. {cmd:iegitaddmd} can solve this by scanning a folder and all its sub-folders for completely empty folders, and create a placeholder file in that folder.{p_end}

{pstd}The solution to use case 1 in {cmd:iegitaddmd} is a Stata adaptation of {it:Solution B} in {browse "http://bytefreaks.net/gnulinux/bash/how-to-add-automatically-all-empty-folders-in-git-repository" :this post}.{p_end}

{pstd}{bf:Use case 2.} A common method when transferring an already ongoing research project to GitHub is to copy all of the data work folder from wherever the files and folders where shared before (for example DropBox) to a clone of the repository. Then only the files that are meant to be shared on GitHub are uploaded to the cloud using a {it:.gitignore file}. Empty folders or folders where all files are ignored is then not shared through GitHub. {cmd:iegitaddmd} can solve this by scanning the DropBox folder (or wherever the project folder was shared before) for sub-folders that exist in that folder but not in the clone and crate that folder in the clone and put a placeholder in it.{p_end}

{pstd}The way you differentiate between these two use cases when using {cmd:iegitaddmd} is whether the option {opt comparefolder()} is used or not. If that option is used, then {cmd:iegitaddmd} will identify all folders that are in {opt comparefolder()} that is not in {opt folder()}, and create a placeholder file there. If {opt comparefolder()} is not used, then {cmd:iegitaddmd} will identify all completely empty folders (no files or subfolders) and create a placeholder file there.{p_end}

{pstd}The default placeholder file used if no file is specified using option {opt customfile()} is called README.md, which is a name and format recognized by GitHub.com so that the content of the file is displayed on GitHub.com when navigating to that folder using a browser. The placeholder file may be removed as	soon as files that are not ignored have been added to the folder, or even better is to keep the file but edit the content of it so it documents the content of that folder for other and future team members.{p_end}

{marker optslong}
{title:Options}

{phang}{opt folder(file_path)} is the folder path to the project folder clone where the placeholder files will be created. Unless option {opt comparefolder()} or {opt all} is used, then placeholder files will be created in all empty folders. See option {opt manual} for a way to manually confirm each folder before a placeholder file is created in it.{p_end}

{phang}{opt comparefolder(file_path)} is used to compare a file tree in a different location and create the folders with placeholder files in all folders that exist in {opt comparefolder()} but not in {opt folder()}. If a folder that does no exist in {opt folder()} has a subfolder, then both the folder and the subfolder will be created and the placeholder file is only crated in the sub-folder. This is enough to share both folder and the subfolder in GitHub. If the {opt comparefolder()} and {opt folder()} ends with folders with different names, for example {opt folder(${project}/datawork/baseline)} and {opt comparefolder(${project}/datawork)}, then the command will throw an error as it is likely that the paths do not point to corresponding folders in the two folder trees. See option {opt manual} for a way to manually confirm each folder before a placeholder file is created in it.{p_end}

{phang}{cmd:file(}{it:{help filename}}{cmd:)} allows the user to specify a file saved on
	the computer to be used as the placeholder file	instead of the default README.md file. This
	allows people and organizations to write their own template placeholder files according to their own
	preferences. We recommend that a file of type .md (markdown) and name README.md is used as
	GitHub.com recognizes this name and format and will display the content of the file when someone
	browse to that folder on GitHub.com. But this is not a technical requirement, any file type
	and name can be used as placeholder file.{p_end}

{phang}{opt all} creates the placeholder file in {opt folder()} and in every subfolder,
	regardless if they are empty or not. This allows the user to create a placeholder file in every
	folder that can be edited with documentation and instructions to the purpose and usage of
	each subfolder. This option can also be important when .{it:gitignore} is used, as {cmd:iegitaddmd} will not
	create files to subfolders that only has ignored file -- in which case the folder will not
	be synced by GitHub.{p_end}

{phang}{opt skip} and {opt replace} tells {cmd:iegitaddmd} what to do if the option {opt all} is used
	and if any of the folders contain a file with the same name as the placeholder file the command
	is trying to create. If a file with the same name as the placeholder file exist and neither of these options
	are used, then the command will throw an error. If {opt skip} is used, then nothing is done in the
	folder where the file with the same name exists and the command proceeds to the next folder.
	If {opt replace} is used then the file with the same name is overwritten with the new placeholder
	file before the command proceeds to the next folder.{p_end}

{phang}{opt skipfolders(folder_name)} can be used to tell {cmd:iegitaddmd} which folders
in which a placeholder file should never be created. The best example of this is the {it:.git}
folder in which placeholders never should be created. That name is always skipped regardless of
this option being used or not. Use this option to list additional folders to be skipped. You
should not list the full folder path in this option, just the folder name. All folders with
that name will be skipped regardless of their location in the project folder. The folder names may
be listed with or without quotation marks as long as there are no spaces in the names. If any of
the folder names has spaces, then quotation marks must be used for all folder names.

{phang}{opt auto:matic} can be used to speed up the creation of placeholders by telling the
command to not prompt the users for confirmation for each file before it is created. The
default is that the command is asking the user before creating each place holder file.
This option should only be used when you are confident you have specified the correct folder
paths. We recommend that you use the {opt dryrun} with this option to make sure that the
folder paths are correct.{p_end}

{phang}{opt dry:run} can be used to safely test that the folder paths are specified correctly
before any placeholder files are created. When this option it used the command simply lists
the file that would have been created if this option were not used. Once you are confident
that list is correct, you can remove this option and re-run the command and the files will
be created.{p_end}

{title:Example}

{pstd}{inp:global github_folder "C:\Users\JohnSmith\Documents\GitHub\ProjectA"}{break}{inp:iegitaddmd , folder({it:"$github_folder"})}{p_end}

{pstd}In the example above, there is a GitHub repository in the folder ProjectA. This
	repository has a folder structure where some folders are still empty but will later
	be populated with files. In order to have all folders, even the empty ones, synced on all
	collaborators' cloned local copies of the repository, the folders need to contain at least
	one file, which is being created by the command.{p_end}

{pstd}{inp:global github_folder "C:\Users\JohnSmith\Documents\GitHub\ProjectB"}{break}{inp:iegitaddmd , folder({it:"$github_folder"}) skipfolders("foo" "bar")}{p_end}

{pstd}In the example above, there is a GitHub repository in the folder ProjectB. This
is a project similar to ProjectA above but it has to folder, called {inp:foo} and {inp:bar}
in which no placeholder files should ever be created in. Any subfolders in {inp:foo}
or {inp:bar} will be skipped as well. The folder {inp:.git} is a system folder in git
repositories and will always be skipped.{p_end}

{title:Author}

{phang}All commands in ietoolkit is developed by DIME Analytics at DECIE, The World Bank's unit for Development Impact Evaluations.

{phang}Author: DIME Analytics, The World Bank Group

{phang}Please send bug-reports, suggestions and requests for clarifications
		 writing "ietoolkit iegitaddmd" in the subject line to:{break}
		 dimeanalytics@worldbank.org

{phang}You can also see the code, make comments to the code, see the version
		 history of the code, and submit additions or edits to the code through {browse "https://github.com/worldbank/ietoolkit":the GitHub repository of ietoolkit}.{p_end}


updates to shocks

updates to shocks

/*-------------------------------------------------------------------------------
# Name:		04_shocks
# 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/04_shocks", replace
set more off

* 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
/* World Bank classifications
	Prices (inputs, outputs, food)
	Hazards (natural, droughts, floods)
	Employment (jobs, wages)
	Assets (house, land, livestock)
	Health (death, illness)
	Crime & Safety (theft, violence)	*/

* Create detailed shocks just in case they are needed
/*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, 116) &  inlist(h16q01, 1) == 1
g byte theft	= inlist(h16q00, 114, 115) &  inlist(h16q01, 1) == 1

g byte priceShk = inlist(h16q00, 106, 107) &  inlist(h16q01, 1) == 1
g byte hazardShk = inlist(h16q00, 101, 102, 103, 117) &  inlist(h16q01, 1) == 1
g byte employShk = inlist(h16q00, 108, 109) &  inlist(h16q01, 1) == 1
g byte assetShk = inlist(h16q00, 104, 105) &  inlist(h16q01, 1) == 1
g byte healthShk = inlist(h16q00, 110, 111, 112, 113) &  inlist(h16q01, 1) == 1
g byte crimeShk = inlist(h16q00, 114, 115, 116) &  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"

la var priceShk "price shocks  (inputs, outputs, food)"
la var hazardShk "hazard schock (flood, fire, drought, landslide)"
la var employShk "Employment (jobs, wages)"
la var assetShk "Assets (house, land, livestock)"
la var healthShk "Health (death, illness)"
la var crimeShk "Crime & Safety (theft, violence)"

* 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 "$pathdo2/copylabels.do"

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

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

* Save shock data and merge with geovars
compress
merge 1:1 HHID using "$pathout/Geovars.dta", gen(geo_merge)
drop geo_merge

* Merge in the data with sampling information
merge 1:1 HHID using "$pathraw\GSEC1.dta", gen(_merge)
keep if _merge==3

* Survey set the data to account for complex sampling design in variance calculations
* svyset comm [pweight=mult], strata(stratum) singleunit(centered)

* Export a cut for GIS work
export delimited "$pathexport/shocks.csv", replace

save "$pathout/shocks.dta", replace
log2html "$pathlog/04_shocks", replace
capture log close

/*-------------------------------------------------------------------------------
# Name:		04_shocks
# 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/04_shocks", replace
set more off

* 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
/* World Bank classifications
	Prices (inputs, outputs, food)
	Hazards (natural, droughts, floods)
	Employment (jobs, wages)
	Assets (house, land, livestock)
	Health (death, illness)
	Crime & Safety (theft, violence)	*/

* Create detailed shocks just in case they are needed
/*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, 116) &  inlist(h16q01, 1) == 1
g byte theft	= inlist(h16q00, 114, 115) &  inlist(h16q01, 1) == 1

g byte priceShk = inlist(h16q00, 106, 107) &  inlist(h16q01, 1) == 1
g byte hazardShk = inlist(h16q00, 101, 102, 103, 117) &  inlist(h16q01, 1) == 1
g byte employShk = inlist(h16q00, 108, 109) &  inlist(h16q01, 1) == 1
g byte assetShk = inlist(h16q00, 104, 105) &  inlist(h16q01, 1) == 1
g byte healthShk = inlist(h16q00, 110, 111, 112, 113) &  inlist(h16q01, 1) == 1
g byte crimeShk = inlist(h16q00, 114, 115, 116) &  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"

la var priceShk "price shocks  (inputs, outputs, food)"
la var hazardShk "hazard schock (flood, fire, drought, landslide)"
la var employShk "Employment (jobs, wages)"
la var assetShk "Assets (house, land, livestock)"
la var healthShk "Health (death, illness)"
la var crimeShk "Crime & Safety (theft, violence)"

* 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 "$pathdo2/copylabels.do"

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

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

* Save shock data and merge with geovars
compress
merge 1:1 HHID using "$pathout/Geovars.dta", gen(geo_merge)
drop geo_merge

* Export a cut for GIS work
export delimited "$pathexport/shocks.csv", replace

save "$pathout/shocks.dta", replace
log2html "$pathlog/04_shocks", replace
capture log close


Update 00_SetupFolderGlobals.do

Update 00_SetupFolderGlobals.do

/*-------------------------------------------------------------------------------
# Name:		00_SetupFolderGlobals
# Purpose:	Create series of folders Food for Uganda Vulnerability Analysis
# Author:	Tim Essam, Ph.D.
# Created:	10/31/2014; 02/19/2015.
# Owner:	USAID GeoCenter | OakStream Systems, LLC
# License:	MIT License
# Ado(s):	see below
#-------------------------------------------------------------------------------
*/

/* RUN/READ ME FIRST -- Make directories for the study.
 1. Requires root name for file folder structure
 2. Requires branch names for sub-folders
 3. Sets global macros for the study; These are used through the do files.
 4. TODO -- Script DOES NOT copy in raw data at this point.
 5. TODO -- Create program folder for calling custom programs.
 6. TODO -- Convert setup .do file into a program (inputs are project path & folder name)
*/

* install the confirm directory ado if not already installed
* list all known user-written .ados needed for project
local required_ados confirmdir mvfiles fs spatgsa  adolist labellist winsor2
foreach x of local required_ados {
	capture findfile `x'.ado
		if _rc==601 {
			cap ssc install `x'
		}
		else disp in yellow "`x' currently installed."
	}
*end

* Determine path for the study
global projectpath "U:\"
*global projectpath "C:\Users\t\Box Sync\"
cd "$projectpath"

* Run a macro to set up study folder (needs to be modified)
* Name the file path below -- replace "nigerlsms" with your folder name
local pFolder UgandaLVAM
foreach dir in `pFolder' {
	confirmdir "`dir'"
	if `r(confirmdir)'==170 {
		mkdir "`dir'"
		display in yellow "Project directory named: `dir' created"
		}
	else disp as error "`dir' already exists, not created."
	cd "$projectpath\`dir'"
	}
* end

* Run initially to set up folder structure
* Choose your folders to set up as the local macro `folders'
local folders Rawdata Stata Datain Log Output Dataout Excel PDF Word Graph GIS Export R Python Programs Sensitive_Data FinalProducts
foreach dir in `folders' {
	confirmdir "`dir'"
	if `r(confirmdir)'==170 {
			mkdir "`dir'"
			disp in yellow "`dir' successfully created."
		}
	else disp as error "`dir' already exists. Skipped to next folder."
}
*end

/*---------------------------------
# Set Globals based on path above #
-----------------------------------*/
global date $S_DATE
local dir `c(pwd)'
global path "`dir'"
global pathdo "`dir'\Stata"
global pathlog  "`dir'\Log"
global pathin "`dir'\Datain"
global pathout "`dir'\Dataout"
global pathgraph "`dir'\Graph"
global pathxls "`dir'\Excel"
global pathreg "`dir'\Output"
global pathgis "`dir'\GIS"
global pathraw "`dir'\Rawdata"
global pathexport "`dir'\Export"
global pathR "`dir'\R"
global pathPython "`dir'\Python"
global pathProgram "`dir'\Program"
global pathPdrive "P:\GeoCenter\GIS\Projects\LVAM\Uganda"
global pathSensitive "`dir'\Sensitive_Data"
global pathProducts "`dir'\FinalProducts"
* Project macros are defined as:
macro list

* Add in subfolders for GIS and Final Products Folders
cd "$pathgis"
local gisfolders FeatureClass Shapefiles csv Layers mxd Rasters scratch
foreach dir in `gisfolders' {
	confirmdir "`dir'"
	if `r(confirmdir)'==170 {
			mkdir "`dir'"
			disp in yellow "`dir' successfully created."
		}
	else disp as error "`dir' already exists. Skipped to next folder."
}
*end

cd "$pathProducts"
local subfolders AI PDFs PosterJPG PPTJPG
foreach dir in `subfolders' {
	confirmdir "`dir'"
	if `r(confirmdir)'==170 {
			mkdir "`dir'"
			disp in yellow "`dir' successfully created."
		}
	else disp as error "`dir' already exists. Skipped to next folder."
}
*end

/*------------------------------------------------------------
# Manually copy raw data  into Datain Folder #

/*-------------------------------------------------------------------------------
# Name:		00_SetupFolderGlobals
# Purpose:	Create series of folders Food for Uganda Vulnerability Analysis
# Author:	Tim Essam, Ph.D.
# Created:	01/12/2014
# Owner:	USAID GeoCenter | OakStream Systems, LLC
# License:	MIT License
# Ado(s):	see below
#-------------------------------------------------------------------------------
*/

/* RUN/READ ME FIRST -- Make directories for the study.
 1. Requires root name for file folder structure
 2. Requires branch names for sub-folders
 3. Sets global macros for the study; These are used through the do files.
 4. TODO -- Script DOES NOT copy in raw data at this point.
 5. TODO -- Create program folder for calling custom programs.
 6. TODO -- Convert setup .do file into a program (inputs are project path & folder name)
*/

* install the confirm directory ado if not already installed
* list all known user-written .ados needed for project
local required_ados confirmdir mvfiles fs spatgsa  adolist labellist winsor2
foreach x of local required_ados {
	capture findfile `x'.ado
		if _rc==601 {
			cap ssc install `x'
		}
		else disp in yellow "`x' currently installed."
	}
*end

* Determine path for the study
global projectpath "U:\"
*global projectpath "C:\Users\t\Box Sync\"
cd "$projectpath"

* Run a macro to set up study folder (needs to be modified)
* Name the file path below -- replace "nigerlsms" with your folder name
local pFolder UgandaLVAM
foreach dir in `pFolder' {
	confirmdir "`dir'"
	if `r(confirmdir)'==170 {
		mkdir "`dir'"
		display in yellow "Project directory named: `dir' created"
		}
	else disp as error "`dir' already exists, not created."
	cd "$projectpath\`dir'"
	}
* end

* Run initially to set up folder structure
* Choose your folders to set up as the local macro `folders'
local folders Rawdata Stata Datain Log Output Dataout Excel PDF Word Graph GIS Export R Python Programs
foreach dir in `folders' {
	confirmdir "`dir'"
	if `r(confirmdir)'==170 {
			mkdir "`dir'"
			disp in yellow "`dir' successfully created."
		}
	else disp as error "`dir' already exists. Skipped to next folder."
}
*end

/*---------------------------------
# Set Globals based on path above #
-----------------------------------*/
global date $S_DATE
local dir `c(pwd)'
global path "`dir'"
global pathdo "`dir'\Stata"
global pathlog  "`dir'\Log"
global pathin "`dir'\Datain"
global pathout "`dir'\Dataout"
global pathgraph "`dir'\Graph"
global pathxls "`dir'\Excel"
global pathreg "`dir'\Output"
global pathgis "`dir'\GIS"
global pathraw "`dir'\Rawdata"
global pathexport "`dir'\Export"
global pathR "`dir'\R"
global pathPython "`dir'\Python"
global pathProgram "`dir'\Program"
global pathPdrive "P:\GeoCenter\GIS\Projects\Ethiopia"

* Project macros are defined as:
macro list

/*------------------------------------------------------------
# Manually copy raw data  into Datain Folder #