Update paths in cscript

Update paths in cscript

* -stgit- cscript

* -version- intentionally omitted for -cscript-.

* 1 to execute profile.do after completion; 0 not to.
local profile 1

/* -------------------------------------------------------------------------- */
					/* initialize			*/

* Check the parameters.
assert inlist(`profile', 0, 1)

* Set the working directory to the stgit directory.
c stgit
cd cscript

cap log close stgit
log using stgit, name(stgit) s replace
di "`c(username)'"
di "`:environment computername'"

clear
if c(stata_version) >= 11 ///
	clear matrix
clear mata
set varabbrev off
set type float
vers 9.2: set seed 234553473
set more off

cd ..
adopath ++ `"`c(pwd)'"'
* Make sure to install -matawarn- (https://github.com/matthew-white/matawarn),
* adding it to a system directory or your ado-path.
cd cscript

timer clear 1
timer on 1

* Preserve select globals.
loc FASTCDPATH : copy glo FASTCDPATH

cscript stgit adofile stgit

* Check that Mata issues no warning messages about the source code.
if c(stata_version) >= 13 {
	loc dir ..
	loc files : dir "`dir'" file *
	foreach file of loc files {
		mata: st_local("ext", pathsuffix(st_local("file")))
		if inlist("`ext'", ".ado", ".mata") {
			matawarn "`dir'/`file'"
			assert !r(warn)
		}
	}
	cscript
}

* Restore globals.
glo FASTCDPATH : copy loc FASTCDPATH

mata: dirs = J(1, 0, "")
* Syntax: pushd: cmd
* Adds the working directory to a stack of directories, then executes
* the command cmd to change the working directory.
pr pushd
	_on_colon_parse `0'
	mata: if (strlen(st_global("s(before)"))) ///
		exit(error(198));;
	mata: dirs = dirs, pwd()
	`s(after)'
end
* Syntax: popd
* Changes the working directory to the directory at the top of the stack of
* directories.
pr popd
	syntax
	mata: st_local("n", strofreal(length(dirs)))
	mata: chdir(dirs[`n'])
	* -chdir()- does not update the working directory bar in the GUI.
	cd .
	if `n' > 1 ///
		mata: dirs = dirs[|1 \ `n' - 1|]
	else ///
		mata: dirs = J(1, 0, "")
end
* Syntax: touch filename
* Creates the new empty file filename.
pr touch
	syntax anything(name=fn id=filename)

	gettoken fn rest : fn
	if `:length loc rest' ///
		err 198

	tempname fh
	file open `fh' using `"`fn'"', w
	file close `fh'
end
* Syntax: assert13 ...
* Executes -assert- if and only if the Stata version is 13 or above.
pr assert13
	if c(stata_version) < 13 ///
		ex
	assert `0'
end

/* -------------------------------------------------------------------------- */
					/* tests				*/

pushd: c stgit_cscript

!git reset --hard
!git clean -dxf
!git checkout master

* Simple test of -stgit status-
stgit status
mata: st_global("git_dir", pathjoin(pwd(), ".git"))
glo sha 2f4069329e877d25890d80811b84cec03f55eec7
pr check_results9
	assert `"`r(git_dir)'"' == `"$git_dir"'
	assert !r(has_detached_head)
	assert "`r(branch)'"    == "master"
	assert "`r(sha)'"       == "$sha"
end
pr check_results_clean
	check_results9

	if c(stata_version) >= 13 {
		assert r(is_clean) == 1
		assert r(has_uncommitted_changes) == 0
		assert "`r(uncommitted_changes)'" == ""
	}
end
check_results_clean

* The -status- subcommand is implied.
stgit
check_results_clean

* Change the working directory to a repository subdirectory.
cd dir
stgit
check_results_clean
* Deprecated syntax
stgit ..
check_results_clean
cd ..

* Test -stgit status, git_dir()-.
foreach root in . "" dir/.. `"`c(pwd)'"' {
	mata: st_local("git_dir", pathjoin(st_local("root"), ".git"))
	stgit status, git_dir(`"`git_dir'"')
	check_results_clean
	stgit, git_dir(`"`git_dir'"')
	check_results_clean

	* Deprecated syntax
	stgit `"`root'"'
	check_results_clean
}
* Nonexistent GIT_DIR
rcof "noi stgit, git_dir(./.git_dir)" == 601
* Bad GIT_DIR
rcof "noi stgit, git_dir(.)" == 198

* Cannot find GIT_DIR.
if c(os) == "Windows" ///
	loc dir C:\
else ///
	loc dir ~
pushd: cd "`dir'"
mata: assert(!direxists(".git"))
rcof "noi stgit" == 601
popd

* Invalid second token
rcof "noi stgit status status" == 101
rcof "noi stgit . ." == 101
rcof "noi stgit ., git_dir(./.git)" == 101
rcof "noi stgit .,git_dir(./.git)" == 101

* Different branch
loc branch master-copy
!git checkout `branch'
stgit
assert !r(has_detached_head)
assert "`r(branch)'" == "`branch'"
!git checkout master
stgit
check_results_clean

* Detached head
!git checkout $sha
stgit
assert `"`r(git_dir)'"' == `"$git_dir"'
assert r(has_detached_head) == 1
assert "`r(branch)'"    == "$sha"
assert "`r(sha)'"       == "$sha"
assert13 r(is_clean) == 1
assert13 !r(has_uncommitted_changes)
!git checkout master

* New files
* Untracked
touch new.txt
stgit
check_results9
assert13 !r(is_clean)
assert13 !r(has_uncommitted_changes)
assert13 "`r(uncommitted_changes)'" == ""
assert13 r(untracked) == "new.txt"
* Added
!git add new.txt
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == "new.txt"
assert13 "`r(untracked)'" == ""
assert13 r(added) == "new.txt"
* Both
touch "new too.txt"
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == "new.txt"
assert13 r(untracked) == `""new too.txt""'
assert13 r(added) == "new.txt"
!git add "new too.txt"
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == `""new too.txt" new.txt"'
assert13 "`r(untracked)'" == ""
assert13 r(added) == `""new too.txt" new.txt"'
* Clean up.
!git reset --hard

* New directory
mkdir new
stgit
check_results_clean
assert13 "`r(untracked)'" == ""
assert13 r(untracked_folders) == "new"
* Second directory
mkdir new2
stgit
check_results_clean
assert13 r(untracked_folders) == "new2 new"
* New file
touch new/new.txt
stgit
check_results9
assert13 !r(is_clean)
assert13 !r(has_uncommitted_changes)
assert13 "`r(uncommitted_changes)'" == ""
assert13 r(untracked) == "new/new.txt"
assert13 r(untracked_folders) == "new2 new"
* Clean up.
!git clean -df

* Remove/modify a tracked file.
* Missing
erase README.md
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == "README.md"
assert13 r(missing) == "README.md"
assert13 "`r(removed)'"  == ""
assert13 "`r(modified)'" == ""
assert13 "`r(changed)'"  == ""
* Removed
!git rm README.md
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == "README.md"
assert13 "`r(missing)'"  == ""
assert13 r(removed) == "README.md"
assert13 "`r(modified)'" == ""
assert13 "`r(changed)'"  == ""
* Modified
!git reset HEAD README.md
touch README.md
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == "README.md"
assert13 "`r(missing)'" == ""
assert13 "`r(removed)'" == ""
assert13 r(modified) == "README.md"
assert13 "`r(changed)'" == ""
* Changed
!git add README.md
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == "README.md"
assert13 "`r(missing)'"  == ""
assert13 "`r(removed)'"  == ""
assert13 "`r(modified)'" == ""
assert13 r(changed) == "README.md"
* Clean up.
!git reset --hard

* Ignored files
* Tracked before .gitignore
tempname fh
file open `fh' using dir/empty.asc, w append
file w `fh' "stgit" _n
file close `fh'
!git add dir/empty.asc
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == "dir/empty.asc"
assert13 r(changed) == "dir/empty.asc"
assert13 "`r(ignored_not_in_index)'" == ""
assert13 "`r(untracked)'" == ""
!git reset --hard
* New ignored file
touch new.asc
stgit
check_results_clean
assert13 r(ignored_not_in_index) == "new.asc"
assert13 "`r(untracked)'" == ""
assert13 "`r(added)'"     == ""
!git clean -xf

* Conflicting files
!git merge conflict
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == ".gitignore"
assert13 r(conflicting)         == ".gitignore"
assert13 "`r(modified)'" == ""
assert13 "`r(changed)'"  == ""
!git merge --abort

popd

/* -------------------------------------------------------------------------- */
					/* finish up			*/

cd ..

timer off 1
timer list 1

if `profile' {
	cap conf f C:\ado\profile.do
	if !_rc ///
		run C:\ado\profile
}

timer list 1

log close stgit

* -stgit- cscript

* -version- intentionally omitted for -cscript-.

* 1 to execute profile.do after completion; 0 not to.
local profile 1

/* -------------------------------------------------------------------------- */
					/* initialize			*/

* Check the parameters.
assert inlist(`profile', 0, 1)

* Set the working directory to the stata-git-tools directory.
c sgt
cd stgit/cscript

cap log close stgit
log using stgit, name(stgit) s replace
di "`c(username)'"
di "`:environment computername'"

clear
if c(stata_version) >= 11 ///
	clear matrix
clear mata
set varabbrev off
set type float
vers 9.2: set seed 234553473
set more off

cd ..
adopath ++ `"`c(pwd)'"'
* Make sure to install -matawarn- (https://github.com/matthew-white/matawarn),
* adding it to a system directory or your ado-path.
cd cscript

timer clear 1
timer on 1

* Preserve select globals.
loc FASTCDPATH : copy glo FASTCDPATH

cscript stgit adofile stgit

* Check that Mata issues no warning messages about the source code.
if c(stata_version) >= 13 {
	loc dir ..
	loc files : dir "`dir'" file *
	foreach file of loc files {
		matawarn "`dir'/`file'"
		assert !r(warn)
	}
	cscript
}

* Restore globals.
glo FASTCDPATH : copy loc FASTCDPATH

mata: dirs = J(1, 0, "")
* Syntax: pushd: cmd
* Adds the working directory to a stack of directories, then executes
* the command cmd to change the working directory.
pr pushd
	_on_colon_parse `0'
	mata: if (strlen(st_global("s(before)"))) ///
		exit(error(198));;
	mata: dirs = dirs, pwd()
	`s(after)'
end
* Syntax: popd
* Changes the working directory to the directory at the top of the stack of
* directories.
pr popd
	syntax
	mata: st_local("n", strofreal(length(dirs)))
	mata: chdir(dirs[`n'])
	* -chdir()- does not update the working directory bar in the GUI.
	cd .
	if `n' > 1 ///
		mata: dirs = dirs[|1 \ `n' - 1|]
	else ///
		mata: dirs = J(1, 0, "")
end
* Syntax: touch filename
* Creates the new empty file filename.
pr touch
	syntax anything(name=fn id=filename)

	gettoken fn rest : fn
	if `:length loc rest' ///
		err 198

	tempname fh
	file open `fh' using `"`fn'"', w
	file close `fh'
end
* Syntax: assert13 ...
* Executes -assert- if and only if the Stata version is 13 or above.
pr assert13
	if c(stata_version) < 13 ///
		ex
	assert `0'
end

/* -------------------------------------------------------------------------- */
					/* tests				*/

pushd: c stgit_cscript

!git reset --hard
!git clean -dxf
!git checkout master

* Simple test of -stgit status-
stgit status
mata: st_global("git_dir", pathjoin(pwd(), ".git"))
glo sha 2f4069329e877d25890d80811b84cec03f55eec7
pr check_results9
	assert `"`r(git_dir)'"' == `"$git_dir"'
	assert !r(has_detached_head)
	assert "`r(branch)'"    == "master"
	assert "`r(sha)'"       == "$sha"
end
pr check_results_clean
	check_results9

	if c(stata_version) >= 13 {
		assert r(is_clean) == 1
		assert r(has_uncommitted_changes) == 0
		assert "`r(uncommitted_changes)'" == ""
	}
end
check_results_clean

* The -status- subcommand is implied.
stgit
check_results_clean

* Change the working directory to a repository subdirectory.
cd dir
stgit
check_results_clean
* Deprecated syntax
stgit ..
check_results_clean
cd ..

* Test -stgit status, git_dir()-.
foreach root in . "" dir/.. `"`c(pwd)'"' {
	mata: st_local("git_dir", pathjoin(st_local("root"), ".git"))
	stgit status, git_dir(`"`git_dir'"')
	check_results_clean
	stgit, git_dir(`"`git_dir'"')
	check_results_clean

	* Deprecated syntax
	stgit `"`root'"'
	check_results_clean
}
* Nonexistent GIT_DIR
rcof "noi stgit, git_dir(./.git_dir)" == 601
* Bad GIT_DIR
rcof "noi stgit, git_dir(.)" == 198

* Cannot find GIT_DIR.
if c(os) == "Windows" ///
	loc dir C:\
else ///
	loc dir ~
pushd: cd "`dir'"
mata: assert(!direxists(".git"))
rcof "noi stgit" == 601
popd

* Invalid second token
rcof "noi stgit status status" == 101
rcof "noi stgit . ." == 101
rcof "noi stgit ., git_dir(./.git)" == 101
rcof "noi stgit .,git_dir(./.git)" == 101

* Different branch
loc branch master-copy
!git checkout `branch'
stgit
assert !r(has_detached_head)
assert "`r(branch)'" == "`branch'"
!git checkout master
stgit
check_results_clean

* Detached head
!git checkout $sha
stgit
assert `"`r(git_dir)'"' == `"$git_dir"'
assert r(has_detached_head) == 1
assert "`r(branch)'"    == "$sha"
assert "`r(sha)'"       == "$sha"
assert13 r(is_clean) == 1
assert13 !r(has_uncommitted_changes)
!git checkout master

* New files
* Untracked
touch new.txt
stgit
check_results9
assert13 !r(is_clean)
assert13 !r(has_uncommitted_changes)
assert13 "`r(uncommitted_changes)'" == ""
assert13 r(untracked) == "new.txt"
* Added
!git add new.txt
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == "new.txt"
assert13 "`r(untracked)'" == ""
assert13 r(added) == "new.txt"
* Both
touch "new too.txt"
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == "new.txt"
assert13 r(untracked) == `""new too.txt""'
assert13 r(added) == "new.txt"
!git add "new too.txt"
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == `""new too.txt" new.txt"'
assert13 "`r(untracked)'" == ""
assert13 r(added) == `""new too.txt" new.txt"'
* Clean up.
!git reset --hard

* New directory
mkdir new
stgit
check_results_clean
assert13 "`r(untracked)'" == ""
assert13 r(untracked_folders) == "new"
* Second directory
mkdir new2
stgit
check_results_clean
assert13 r(untracked_folders) == "new2 new"
* New file
touch new/new.txt
stgit
check_results9
assert13 !r(is_clean)
assert13 !r(has_uncommitted_changes)
assert13 "`r(uncommitted_changes)'" == ""
assert13 r(untracked) == "new/new.txt"
assert13 r(untracked_folders) == "new2 new"
* Clean up.
!git clean -df

* Remove/modify a tracked file.
* Missing
erase README.md
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == "README.md"
assert13 r(missing) == "README.md"
assert13 "`r(removed)'"  == ""
assert13 "`r(modified)'" == ""
assert13 "`r(changed)'"  == ""
* Removed
!git rm README.md
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == "README.md"
assert13 "`r(missing)'"  == ""
assert13 r(removed) == "README.md"
assert13 "`r(modified)'" == ""
assert13 "`r(changed)'"  == ""
* Modified
!git reset HEAD README.md
touch README.md
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == "README.md"
assert13 "`r(missing)'" == ""
assert13 "`r(removed)'" == ""
assert13 r(modified) == "README.md"
assert13 "`r(changed)'" == ""
* Changed
!git add README.md
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == "README.md"
assert13 "`r(missing)'"  == ""
assert13 "`r(removed)'"  == ""
assert13 "`r(modified)'" == ""
assert13 r(changed) == "README.md"
* Clean up.
!git reset --hard

* Ignored files
* Tracked before .gitignore
tempname fh
file open `fh' using dir/empty.asc, w append
file w `fh' "stgit" _n
file close `fh'
!git add dir/empty.asc
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == "dir/empty.asc"
assert13 r(changed) == "dir/empty.asc"
assert13 "`r(ignored_not_in_index)'" == ""
assert13 "`r(untracked)'" == ""
!git reset --hard
* New ignored file
touch new.asc
stgit
check_results_clean
assert13 r(ignored_not_in_index) == "new.asc"
assert13 "`r(untracked)'" == ""
assert13 "`r(added)'"     == ""
!git clean -xf

* Conflicting files
!git merge conflict
stgit
check_results9
assert13 !r(is_clean)
assert13 r(has_uncommitted_changes) == 1
assert13 r(uncommitted_changes) == ".gitignore"
assert13 r(conflicting)         == ".gitignore"
assert13 "`r(modified)'" == ""
assert13 "`r(changed)'"  == ""
!git merge --abort

popd

/* -------------------------------------------------------------------------- */
					/* finish up			*/

cd ..

timer off 1
timer list 1

if `profile' {
	cap conf f C:\ado\profile.do
	if !_rc ///
		run C:\ado\profile
}

timer list 1

log close stgit


more output in deleteFolder

more output in deleteFolder

	cap program drop   deleteFolder
		program define deleteFolder

	args folder

	noi di "`folder'"

	local flist : dir `"`folder'"' files "*"
	local dlist : dir `"`folder'"' dirs "*"
	local olist : dir `"`folder'"' other "*"

	foreach file of local flist {
		noi di "`folder'\\`file'"
		if "`c(os)'" == "Windows" erase "`folder'\\`file'"
		if "`c(os)'" != "Windows" rm 	"`folder'\\`file'"
	}
	foreach file of local olist {
		noi di "`folder'\\`file'"
		if "`c(os)'" == "Windows" erase "`folder'\\`file'"
		if "`c(os)'" != "Windows" rm 	"`folder'\\`file'"
	}
	foreach dir of local dlist {

		deleteFolder "`folder'\\`dir'"
	}

	rmdir "`folder'"

end

	cap program drop   deleteFolder
		program define deleteFolder

	args folder

	noi di "`folder'"

	local flist : dir `"`folder'"' files "*"
	local dlist : dir `"`folder'"' dirs "*"
	local olist : dir `"`folder'"' other "*"

	foreach file of local flist {

		if "`c(os)'" == "Windows" erase "`folder'\\`file'"
		if "`c(os)'" != "Windows" rm 	"`folder'\\`file'"
	}
	foreach file of local olist {

		if "`c(os)'" == "Windows" erase "`folder'\\`file'"
		if "`c(os)'" != "Windows" rm 	"`folder'\\`file'"
	}
	foreach dir of local dlist {

		deleteFolder "`folder'\\`dir'"
	}

	rmdir "`folder'"

end


Added information on exporting the graphs.

{smcl}
{* 26 Dec 2016}{...}
{hline}
help for {hi:iegraph}
{hline}

{title:Title}

{phang2}{cmdab:iegraph} {hline 2} Generates graphs based on regressions with treatment dummies common in impact evaluations.

{title:Syntax}

{phang2}
{cmdab:iegraph} {varlist}
, [{cmd:noconfbars} {cmdab:ti:tle(}{it:string}{cmd:)}
{cmdab:save(}{it:string}{cmd:)} {cmdab:confbarsnone(}{it:varlist}{cmd:)}
{it:any towway graph options}
]

{marker opts}{...}
{synoptset 22}{...}
{synopthdr:options}
{synoptline}
{synopt :{cmd:noconfbars}} Removes the confidence interval bars from graphs for all treatments.{p_end}
{synopt :{cmdab:ti:tle(}{it:string}{cmd:)}} Manually sets the title of the graph.{p_end}
{synopt :{cmdab:save(}{it:string}{cmd:)}} Sets the filename and the directory to which the graph will be set/exported.{p_end}
{synopt :{cmdab:confbarsnone(}{it:varlist}{cmd:)}} Removes confidence interval bars from only the {it:varlist} listed.{p_end}
{synopt :{cmdab:yzero}} Forces y-axis on the graph to start at 0.{p_end}
{synopt :{cmdab: Graph Options}} Options that can be used with normal graph commands can also be used. See example 2 for details.{p_end}
{synoptline}

{marker desc}
{title:Description}

{pstd}{cmdab:iegraph} This command creates bar graphs on the based on the coefficients
	of treatment dummies in regression results. This command is developed for reading
	stored results of from two types of impact evaluation regression models, but there
	are countless of other examples where the command also can be used. {cmd:iegraph} must
	be used immediately after running the regression or as long as the regression result is
	still stored in or restored to Stata's {help ereturn} results.

{pstd}{bf:Model 1: OLS with Treatment Dummies}{break}The most typical impact evaluation regression is
	to have the outcome variable as the dependent variable and one dummy for each
	treatment arm where control is the omitted category. These regressions can also include
	covariates, fixed effects etc., but as long as the treatment status is defined by
	mutually exclusive dummy variables. See especially example 1 and 2 below. This command
	works with any number of treatment arms but works best from two arms (treatment
	and control) to five treatment arms (4 different treatments and control). More
	arms than that may result in a still correct but perhaps cluttered graph.

{pstd}{bf:Model 2: Difference-in-Differences}{break}Another typical regression model in impact
	evaluations are difference-in-difference (Diff-in-Diff) models with two treatment arms (treatment
	and control) and two time periods. If the Diff-in-Diff regression is specified as having the
	outcome variable as the dependent variable and three dummy variables (time, treatment
	and timeXtreatment) as the independent variables, then this command will produce a nice
	graph. Controls, treatment effects etc. may be added to the regression model. See especially example 3.

{pstd}{bf:Graph Output}{break}The graph generated by this command is created using the following values. The
	control bar is the mean of the outcome variable for the control group. It is not
	the constant from the regression as those are not identical if, for example, fixed effects
	and covariates were used. For each treatment group the bar is the sum of the value
	of the control bar and the beta coefficient in the regression of the corresponding
	treatment dummy. The confidence intervals are calculated from the variance in the
	beta coefficients in the regression.{p_end}

{pstd}The graph also includes the N for each treatment arm in the regression and uses
	that value as labels on the x-axis. Stars are added to this value if the corresponding
	coefficient is statistically different from zero in the regression{p_end}

{marker optslong}
{title:Options}

{phang}{cmd:noconfbars} Removes the confidence interval bars from graphs for all
	treatments. The default value for the confidence interval bars ar 95%. {p_end}

{phang}{cmdab:ti:tle(}{it:string}{cmd:)} Manually sets the title of the graph.{p_end}

{phang}{cmdab:save(}{it:string}{cmd:)} Sets the filename and the directory to which
	the graph will be set. If the filename ends with no extension or '.gph', it will be
	saved in the graph format. Extensions(png,pdf,tif,wmf,emf,ps,and eps) will be exported.
	Wmf and Emf are only available for the Windows version of Stata. Png and Tif for all
	versions of Stata except Console.{p_end}

{phang}{cmdab:confbarsnone(}{it:varlist}{cmd:)} Removes confidence interval bars
	from only the {it:varlist} listed. The remaining variables in the graphs which
	have not been specified in {cmdab:confbarsnone} will still have the confidence
	interval bars. {p_end}

{phang}{cmdab:yzero} Manually sets the y-axis of the graph to start at zero instead of the Stata default.{p_end}

{marker optslong}
{title:Examples}

{pstd} {hi:Example 1.}

{pmore} {inp:regress} {it:outcomevar treatment_dummy}{break}
		{inp:iegraph} {it:treatment_dummy} , {inp:title({it:"Treatment Effect on Outcome"})}

{pmore}In the example above, there is only two treatment arms (treatment and
		control). {it:treatment_dummy} has a 1 for all treatment observations and
		a 0 for all control observations. The graph will have one bar for control and
		it shows the mean for {it:outcomevar} for all observations in control. The
		second bar in the graph will be the sum of that mean and the coefficient
		for {it:treatment_dummy} in the regression. The graph will also have the
		title: Treatment Effect on Outcome.

{pstd} {hi:Example 2.}

{pmore} {inp:regress} {it:income tmt_1 tmt_2 age education}{inp:, cluster(}{it:district}{inp:)}{break}
		{inp:iegraph} {it:tmt_1 tmt_2}{inp:, noconfbars yzero title({it:"Treatment effect on income"}) }

{pmore}In the example above, the treatment effect on income in reserached. There
		are three treatment arms; control, treatment 1 ({it:tmt_1}) and treatment
		2 ({it:tmt_2}). It is important that no observation has the value 1 in
		both {it:tmt_1} and {it:tmt_2} (i.e. no observation is in more than one
		treatment) and some observations must have the value 0 in both {it:tmt_1}
		and {it:tmt_2} (i.e. control observations). The variables {it:age} and
		{it:education} are covariates (control variables) and is not included
		in {cmd:iegraph}. {inp:noconfbars} omitts the confidence intervall bars
		, and {inp:yzero} sets the y-axis to start at 0.

{pstd} {hi:Example 3.}

{pmore} {inp:regress} {it:chld_wght time treat timeXtreat}{break}
		{inp:iegraph} {it:time treat timeXtreat} {inp:, title({it:"Treatment effect on Child Weight (Diff-in-Diff)"})}

{pmore}In the example above, the data set is a panel data set with two time
		periods and the regression estimates the treatment effect on child weight
		using a Difference-in-Differences model.
		The dummy variable {it:time} indicates if it is time period 0 or 1.
		The dummy variable {it:treat} indicates if the observation is treatment
		or control. {it:timeXtreat} is the interaction term of {it:time}
		and {it:treat}. This the standard way to set up a Difference-in-Differences
		regression model.

{pstd} {hi:Example 4.}

{pmore} {inp:regress} {it:harvest T1 T2 T3 } {break}
		{inp:iegraph} {it:T1 T2 T3} {inp:, title({it:"Treatment effect on harvest"})
		xlabel(,angle(45)) yzero ylabel(minmax) save({it:"$Output/Graph1.gph"})}

{pmore}The example above shows how to save a graph to disk. It also shows that
	most two-way graph options can be used. In this example the {cmd:iegraph}
	option {cdm:yzero} conflicts with the two-way option {cmd:ylabel(minmax)}.
	In such a case the user specified option takes presidence over {cmd:iegraph}
	options like {cdm:yzero}.

{title:Acknowledgements}

{phang}We would like to acknowledge the help in testing and proofreading we received in relation to this command and help file from (in alphabetic order):{p_end}
{pmore}Luiza Cardoso De Andrade{break}Michael Orevba{break}Ahmad Zia Wahdat{break}

{title:Authors}

{phang}Kristoffer Bjarkefur & Mrijan Rimal, The World Bank, DECIE

{phang}Please send bug-reports, suggestions and requests for clarifications
		 writing "ietoolkit iegraph" in the subject line to:{break}
		 kbjarkefur@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
		 the github repository of ietoolkit:{break}
		 {browse "https://github.com/worldbank/ietoolkit"}

{smcl}
{* 26 Dec 2016}{...}
{hline}
help for {hi:iegraph}
{hline}

{title:Title}

{phang2}{cmdab:iegraph} {hline 2} Generates graphs based on regressions with treatment dummies common in impact evaluations.

{title:Syntax}

{phang2}
{cmdab:iegraph} {varlist}
, [{cmd:noconfbars} {cmdab:ti:tle(}{it:string}{cmd:)}
{cmdab:save(}{it:string}{cmd:)} {cmdab:confbarsnone(}{it:varlist}{cmd:)}
{it:any towway graph options}
]

{marker opts}{...}
{synoptset 22}{...}
{synopthdr:options}
{synoptline}
{synopt :{cmd:noconfbars}} Removes the confidence interval bars from graphs for all treatments.{p_end}
{synopt :{cmdab:ti:tle(}{it:string}{cmd:)}} Manually sets the title of the graph.{p_end}
{synopt :{cmdab:save(}{it:string}{cmd:)}} Sets the filename and the directory to which the graph will be set.{p_end}
{synopt :{cmdab:confbarsnone(}{it:varlist}{cmd:)}} Removes confidence interval bars from only the {it:varlist} listed.{p_end}
{synopt :{cmdab:yzero}} Forces y-axis on the graph to start at 0.{p_end}
{synopt :{cmdab: Graph Options}} Options that can be used with normal graph commands can also be used. See example 2 for details.{p_end}
{synoptline}

{marker desc}
{title:Description}

{pstd}{cmdab:iegraph} This command creates bar graphs on the based on the coefficients
	of treatment dummies in regression results. This command is developed for reading
	stored results of from two types of impact evaluation regression models, but there
	are countless of other examples where the command also can be used. {cmd:iegraph} must
	be used immediately after running the regression or as long as the regression result is
	still stored in or restored to Stata's {help ereturn} results.

{pstd}{bf:Model 1: OLS with Treatment Dummies}{break}The most typical impact evaluation regression is
	to have the outcome variable as the dependent variable and one dummy for each
	treatment arm where control is the omitted category. These regressions can also include
	covariates, fixed effects etc., but as long as the treatment status is defined by
	mutually exclusive dummy variables. See especially example 1 and 2 below. This command
	works with any number of treatment arms but works best from two arms (treatment
	and control) to five treatment arms (4 different treatments and control). More
	arms than that may result in a still correct but perhaps cluttered graph.

{pstd}{bf:Model 2: Difference-in-Differences}{break}Another typical regression model in impact
	evaluations are difference-in-difference (Diff-in-Diff) models with two treatment arms (treatment
	and control) and two time periods. If the Diff-in-Diff regression is specified as having the
	outcome variable as the dependent variable and three dummy variables (time, treatment
	and timeXtreatment) as the independent variables, then this command will produce a nice
	graph. Controls, treatment effects etc. may be added to the regression model. See especially example 3.

{pstd}{bf:Graph Output}{break}The graph generated by this command is created using the following values. The
	control bar is the mean of the outcome variable for the control group. It is not
	the constant from the regression as those are not identical if, for example, fixed effects
	and covariates were used. For each treatment group the bar is the sum of the value
	of the control bar and the beta coefficient in the regression of the corresponding
	treatment dummy. The confidence intervals are calculated from the variance in the
	beta coefficients in the regression.{p_end}

{pstd}The graph also includes the N for each treatment arm in the regression and uses
	that value as labels on the x-axis. Stars are added to this value if the corresponding
	coefficient is statistically different from zero in the regression{p_end}

{marker optslong}
{title:Options}

{phang}{cmd:noconfbars} Removes the confidence interval bars from graphs for all
	treatments. The default value for the confidence interval bars ar 95%. {p_end}

{phang}{cmdab:ti:tle(}{it:string}{cmd:)} Manually sets the title of the graph.{p_end}

{phang}{cmdab:save(}{it:string}{cmd:)} Sets the filename and the directory to which
	the graph will be set.{p_end}

{phang}{cmdab:confbarsnone(}{it:varlist}{cmd:)} Removes confidence interval bars
	from only the {it:varlist} listed. The remaining variables in the graphs which
	have not been specified in {cmdab:confbarsnone} will still have the confidence
	interval bars. {p_end}

{phang}{cmdab:yzero} Manually sets the y-axis of the graph to start at zero instead of the Stata default.{p_end}

{marker optslong}
{title:Examples}

{pstd} {hi:Example 1.}

{pmore} {inp:regress} {it:outcomevar treatment_dummy}{break}
		{inp:iegraph} {it:treatment_dummy} , {inp:title({it:"Treatment Effect on Outcome"})}

{pmore}In the example above, there is only two treatment arms (treatment and
		control). {it:treatment_dummy} has a 1 for all treatment observations and
		a 0 for all control observations. The graph will have one bar for control and
		it shows the mean for {it:outcomevar} for all observations in control. The
		second bar in the graph will be the sum of that mean and the coefficient
		for {it:treatment_dummy} in the regression. The graph will also have the
		title: Treatment Effect on Outcome.

{pstd} {hi:Example 2.}

{pmore} {inp:regress} {it:income tmt_1 tmt_2 age education}{inp:, cluster(}{it:district}{inp:)}{break}
		{inp:iegraph} {it:tmt_1 tmt_2}{inp:, noconfbars yzero title({it:"Treatment effect on income"}) }

{pmore}In the example above, the treatment effect on income in reserached. There
		are three treatment arms; control, treatment 1 ({it:tmt_1}) and treatment
		2 ({it:tmt_2}). It is important that no observation has the value 1 in
		both {it:tmt_1} and {it:tmt_2} (i.e. no observation is in more than one
		treatment) and some observations must have the value 0 in both {it:tmt_1}
		and {it:tmt_2} (i.e. control observations). The variables {it:age} and
		{it:education} are covariates (control variables) and is not included
		in {cmd:iegraph}. {inp:noconfbars} omitts the confidence intervall bars
		, and {inp:yzero} sets the y-axis to start at 0.

{pstd} {hi:Example 3.}

{pmore} {inp:regress} {it:chld_wght time treat timeXtreat}{break}
		{inp:iegraph} {it:time treat timeXtreat} {inp:, title({it:"Treatment effect on Child Weight (Diff-in-Diff)"})}

{pmore}In the example above, the data set is a panel data set with two time
		periods and the regression estimates the treatment effect on child weight
		using a Difference-in-Differences model.
		The dummy variable {it:time} indicates if it is time period 0 or 1.
		The dummy variable {it:treat} indicates if the observation is treatment
		or control. {it:timeXtreat} is the interaction term of {it:time}
		and {it:treat}. This the standard way to set up a Difference-in-Differences
		regression model.

{pstd} {hi:Example 4.}

{pmore} {inp:regress} {it:harvest T1 T2 T3 } {break}
		{inp:iegraph} {it:T1 T2 T3} {inp:, title({it:"Treatment effect on harvest"})
		xlabel(,angle(45)) yzero ylabel(minmax) save({it:"$Output/Graph1.gph"})}

{pmore}The example above shows how to save a graph to disk. It also shows that
	most two-way graph options can be used. In this example the {cmd:iegraph}
	option {cdm:yzero} conflicts with the two-way option {cmd:ylabel(minmax)}.
	In such a case the user specified option takes presidence over {cmd:iegraph}
	options like {cdm:yzero}.

{title:Acknowledgements}

{phang}We would like to acknowledge the help in testing and proofreading we received in relation to this command and help file from (in alphabetic order):{p_end}
{pmore}Michael Orevba{break}Ahmad Zia Wahdat{break}

{title:Author}

{phang}Kristoffer Bjarkefur & Mrijan Rimal, The World Bank, DECIE

{phang}Please send bug-reports, suggestions and requests for clarifications
		 writing "ietoolkit iegraph" in the subject line to:{break}
		 kbjarkefur@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
		 the github repository of ietoolkit:{break}
		 {browse "https://github.com/worldbank/ietoolkit"}


sim: add signal to reg tb waveform

sim: add signal to reg tb waveform

onerror {resume}
quietly WaveActivateNextPane {} 0
add wave -noupdate /zwishbone_regs_tb/clk
add wave -noupdate /zwishbone_regs_tb/reset
add wave -noupdate /zwishbone_regs_tb/en_i
add wave -noupdate /zwishbone_regs_tb/we_i
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/adr_i
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/dat_o
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/dat_i
add wave -noupdate /zwishbone_regs_tb/err_i
add wave -noupdate /zwishbone_regs_tb/rty_i
add wave -noupdate /zwishbone_regs_tb/busy_o
add wave -noupdate /zwishbone_regs_tb/ready_o
add wave -noupdate -divider inside
add wave -noupdate /zwishbone_regs_tb/c_regs/clk_i
add wave -noupdate /zwishbone_regs_tb/c_regs/rst_i
add wave -noupdate /zwishbone_regs_tb/c_regs/en_i
add wave -noupdate /zwishbone_regs_tb/c_regs/we_i
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/c_regs/adr_i
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/c_regs/dat_i
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/c_regs/dat_o
add wave -noupdate /zwishbone_regs_tb/c_regs/busy_o
add wave -noupdate /zwishbone_regs_tb/c_regs/ready_o
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/c_regs/cfg_o
add wave -noupdate /zwishbone_regs_tb/c_regs/err_i
add wave -noupdate /zwishbone_regs_tb/c_regs/rty_i
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/c_regs/reg_config
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/c_regs/reg_status
add wave -noupdate /zwishbone_regs_tb/c_regs/ready_r
add wave -noupdate /zwishbone_regs_tb/c_regs/reading_r
TreeUpdate [SetDefaultTree]
WaveRestoreCursors {{Cursor 1} {0 ps} 0}
quietly wave cursor active 1
configure wave -namecolwidth 271
configure wave -valuecolwidth 82
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 ms
update
WaveRestoreZoom {0 ps} {229312 ps}

onerror {resume}
quietly WaveActivateNextPane {} 0
add wave -noupdate /zwishbone_regs_tb/clk
add wave -noupdate /zwishbone_regs_tb/reset
add wave -noupdate /zwishbone_regs_tb/en_i
add wave -noupdate /zwishbone_regs_tb/we_i
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/adr_i
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/dat_o
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/dat_i
add wave -noupdate /zwishbone_regs_tb/err_i
add wave -noupdate /zwishbone_regs_tb/rty_i
add wave -noupdate /zwishbone_regs_tb/busy_o
add wave -noupdate /zwishbone_regs_tb/ready_o
add wave -noupdate -divider inside
add wave -noupdate /zwishbone_regs_tb/c_regs/clk_i
add wave -noupdate /zwishbone_regs_tb/c_regs/rst_i
add wave -noupdate /zwishbone_regs_tb/c_regs/en_i
add wave -noupdate /zwishbone_regs_tb/c_regs/we_i
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/c_regs/adr_i
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/c_regs/dat_i
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/c_regs/dat_o
add wave -noupdate /zwishbone_regs_tb/c_regs/busy_o
add wave -noupdate /zwishbone_regs_tb/c_regs/ready_o
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/c_regs/cfg_o
add wave -noupdate /zwishbone_regs_tb/c_regs/err_i
add wave -noupdate /zwishbone_regs_tb/c_regs/rty_i
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/c_regs/reg_config
add wave -noupdate -radix hexadecimal /zwishbone_regs_tb/c_regs/reg_status
add wave -noupdate /zwishbone_regs_tb/c_regs/ready_r
TreeUpdate [SetDefaultTree]
WaveRestoreCursors {{Cursor 1} {0 ps} 0}
quietly wave cursor active 1
configure wave -namecolwidth 271
configure wave -valuecolwidth 82
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 ms
update
WaveRestoreZoom {0 ps} {229312 ps}