Update and rename Stata to Stata/02_hhchar.do

/*------------------------------------------------------------------------------
# Name:		02_hhchar
# Purpose:	Process household characteristics and education characteristics
# Author:	Patrick Gault
# Created:	2015/2/21
# License:	MIT License
# Ado(s):	labutil, labutil2 (ssc install labutil, labutil2)
# Dependencies: copylables, attachlabels, 00_SetupFoldersGlobals.do
#-------------------------------------------------------------------------------
*/

clear
capture log close
log using "$pathlog/01_hhchar.log", replace

use "$pathraw/GSEC2.dta", replace

* Merge education data to household roster using the force command
merge 1:1 HHID PID using "$pathraw/GSEC4.dta", force

/* Demographic list to calculate
1. Head of Household Sex
2. Relationship Status
*/

* Create head of household variable based on primary respondent and sex
g byte hoh = h2q4 == 1
la var hoh "Head of household"

g byte femhead = h2q3 == 2 & h2q4 == 1
la var femhead "Female head of household"

g agehead = h2q8 if hoh == 1
la var agehead "Age of head of household"

g ageheadsq = agehead^2
la var ageheadsq "Squared age of the head (for non-linear effects)"

* Relationship status variables
g byte marriedHohm = h2q10 == 1 & hoh==1
la var marriedHohm "married HOH monogamous"

g byte marriedHoh = hoh ==1 & inlist(h2q10, 1, 2)
la var marriedHoh "married head of household (any type)"

g byte marriedHohp = h2q10 == 2 & hoh==1
la var marriedHohp "married HOH polygamous"

g byte divorcedHead = (h2q10 == 3 & hoh==1)
la var divorcedHead "divorced HoH"

g byte divorcedFemhead = (h2q10 == 3 & femhead == 1)
la var divorcedFemhead "divorced Female head of household"

g byte widowHead = (h2q10 == 4 & hoh==1)
la var widowHead "widowed HoH"

g byte widowFemhead = (h2q10 == 4 & femhead == 1)
la var widowFemhead "Widowed Female head of household"

g byte singleHead = (h2q10==5 & hoh==1)
la var singleHead "single HoH"

g byte singleFemhead = (h2q10==5 & femhead)
la var singleFemhead "single HoH"

* Calculate household demographics (size, adult equivalent units, dep ratio, etc).

/* Household size - Household size refers to the number of usual members in a
household. Usual members are defined as those who have lived in the household
for at least 6 months in the past 12 months. However, it includes persons who
may have spent less than 6 months during the last 12 months in the household
but have joined the household with intention to live permanently or for an
extended period of time.
* http://www.ubos.org/UNHS0910/chapter2_householdcharacteristics.html */

*Create a flag variable for determining who is a usual member from above.
g byte hhmemb = (inlist(h2q7, 1, 2) & h2q5 >= 6)
egen hhsize = total(hhmemb), by(HHID)

* Create sex ratio for households
g byte male = h2q3 == 1 & hhmemb == 1
g byte female = h2q3 == 2 & hhmemb == 1
la var male "male hh members"
la var female "female hh members"

egen msize = total(male), by(HHID)
la var msize "number of males in hh"

egen fsize = total(female), by(HHID)
la var fsize "number of females in hh"

* Create a gender ratio variable
g sexRatio = msize/fsize
recode sexRatio (. = 0) if fsize==0
la var sexRatio "Ratio of males to females in HH"

* Calculate age demographics
g byte under15tmp = h2q8 <= 15 & hhmemb ==1
g byte under24tmp = h2q8 <= 24 &  hhmemb==1

egen under15 = total(under15tmp), by(HHID)
la var under15 "number of hh members under 15 years old"

egen under24 = total(under24tmp), by(HHID)
la var under15 "number of hh members under 24 years old"

egen under15male = total(under15tmp) if male==1, by(HHID)
la var under15male "number of male hh members under 15"

egen under15female = total(under15tmp) if female==1, by(HHID)
la var under15female "number of female hh members under 15"

egen under24male = total(under24tmp) if male==1, by(HHID)
la var under24male "number of male hh members under 24"

egen under24female = total(under24tmp) if female==1, by(HHID)
la var under24female "number of female hh members under 24"

/* Create intl. HH dependency ratio (age ranges appropriate for Bangladesh)
# HH Dependecy Ratio = [(# people 0-14 + those 65+) / # people aged 15-64 ] * 100 #
The dependency ratio is defined as the ratio of the number of members in the age groups
of 0–14 years and above 60 years to the number of members of working age (15–60 years).
The ratio is normally expressed as a percentage (data below are multiplied by 100 for pcts.*/
g byte numDepRatio = (h2q8 < 15 | h2q8 > 64) & hhmemb == 1
g byte demonDepRatio = numDepRatio != 1 & hhmemb == 1
egen totNumDepRatio = total(numDepRatio), by(HHID)
egen totDenomDepRatio = total(demonDepRatio), by(HHID)

* Check that numbers add to hhsize
assert hhsize == totNumDepRatio+totDenomDepRatio if hhmemb==1
g depRatio = (totNumDepRatio/totDenomDepRatio)*100 if totDenomDepRatio!=.
recode depRatio (. = 0) if totDenomDepRatio==0
la var depRatio "Dependency Ratio"

* Calculate household labor shares (ages 12 - 60)
/* Household Labor Shares */
g byte hhLabort = (h2q8>= 12 & h2q8<60) & hhmemb == 1
egen hhlabor = total(hhLabort), by(HHID)
la var hhlabor "hh labor age>11 & < 60"

g byte mlabort = (h2q8>= 12 & h2q8<60 & male == 1)
egen mlabor = total(mlabort), by(HHID)
la var mlabor "hh male labor age>11 & <60"

g byte flabort = (h2q8>= 12 & h2q8<60 & female == 2)
egen flabor = total(flabort), by(HHID)
la var flabor "hh female labor age>11 & <60"
drop hhLabort mlabort flabort

* Male/Female labor share in hh
g mlaborShare = mlabor/hhlabor
recode mlaborShare (. = 0) if hhlabor == 0
la var mlaborShare "share of working age males in hh"

g flaborShare = flabor/hhlabor
recode flaborShare (. = 0) if hhlabor == 0
la var flaborShare "share of working age females in hh"

* Generate adult equivalents in household
g male10 	= 1
g fem10_19 	= 0.84
g fem20		= 0.72
g child10	= 0.60

g ae = .
replace ae = male10 if (h2q8 >=10 ) & male == 1
replace ae = fem10_19 if (h2q8 >= 10 & h2q8 < 20) & female == 1
replace ae = fem20 if (h2q8 >= 20) & female == 1
replace ae = child10 if (h2q8) < 10 & hhmemb == 1
la var ae "Adult equivalents"

egen adultEquiv = total(ae), by(HHID)
la var adultEquiv "Total adult equivalent units"

**********************
* Education outcomes *
**********************

* Save
save "$pathout/hhchar.dta", replace

* Keep a master file of only household id's for missing var checks
keep HHID PID
save "$pathout\hhid.dta", replace

* Create an html file of the log for internet sharability
log2html "$pathlog/02_hhchar", replace
log close

error: pathspec 'Stata/02_hhchar.do' did not match any file(s) known to git


initial stages

initial stages

insheet using ${rawhist}node_gc.csv, clear

renamevar
cleanvar

program cleanvar

gen tstamp = timestamp*1000 + msofhours(24)*3653 - msofhours(5)
format tstamp %tc

gen tstamp_date = dofc(tstamp)
format tstamp_date %td

gen month = mofd(tstamp_date)
format month %tm

// drop non-US items
drop if fips == "NA" & geoid10 == "NA"

// drop gnis data
drop if gnisfid != "NA" & version == 1

end

program renamevar
rename v1 amenity
rename v2 addr
rename v3 place
rename v4 user
rename v5 uid
rename v6 timestamp
rename v7 version
rename v8 changeset
rename v9 lon
rename v10 lat
rename v11 id
rename v12 name
rename v13 gnisfid
rename v14 gnisfcode
rename v15 fips
rename v16 geoid10
end

error: pathspec 'stata/preparenode.ado' did not match any file(s) known to git


Added STATA version of pairwise comparisons post-regression

sysuse auto
regress price i.rep78

* First approach: Change baseline
regress price ib2.rep78

* Second approach: Use margins to view all pairwise
* (effects) gives both P-value and CI, use (pv) or (ci) for just one or the otehr
regress price i.rep78
margins rep78, pwcompare(eff)

error: pathspec 'statistics/pairwise_comp_marginal_means/pairwise_comp_marginal_means.do' did not match any file(s) known to git


New functionalities

New functionalities

fatal: unable to access 'https://github.com/gvegayon/parallel.git/': The requested URL returned error: 403


missing .do file

missing .do file

redo-ifchange dxforth/dxforth.bin
cp dxforth/dxforth.bin $3

error: pathspec 'software/src/e2/rom-image.bin.do' did not match any file(s) known to git


clean.do: clean up .redo files for sanity.

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/pombredanne/redo.git/'


(Benchmark) Hardest case for solver (Fix #15)

- The two FEs in this example are "interlaced".
- Combined with the particular values for the LHS, solving this will
take a lot of iterations...

In this extreme case, any direct method (areg, projvar, felsdvreg?) is
better than an indirect method.

- Note that CG+SYM is still fast, SD+KAC slow, and AITKEN+anything is
very slow
- Also note that a simple GT preconditioner for CG+SYM fixes this
problem

* This is "the hardest case ever" for iterative methods
* In this case, just use a direct one (areg/res2fe/etc)

clear all
cls
set more off

local N 100

set obs `N'
gen id1 = 1 + int((_n-1)/2)
gen id2 = 1 + int((_n)/2)
gen n = 1 + (_n==1 | _n==_N)
expand n
drop n

sort id1 id2
li id1 id2, sep(0)

cap drop y
gen y = (_n==1) // (_n==_N)
gen x = uniform()

do twowayreg.ado
tic
di "twowayset"
twowayset id1 id2
di "projvar"
projvar y x, p(w_)
reg w*, noc robust
drop w_*
toc, report

tic
reghdfe y x, absorb(id1 id2) dof(none) tol(1e-10) fast
// v(3) accel(cg) transf(sym) keepsing clear // fast
toc, report

exit

* alternatives:
reg2hdfe y, id1(id1) id2(id2) tol(1e-8) // verbose // 5000 iters
exit

*hdfe  y, absorb(id1 id2) dof(none) tol(1e-10) v(3) accel(a) transf(kac) keepsing clear // fast
hdfe  y, absorb(id1 id2) dof(none) tol(1e-10) v(3) accel(cg) transf(sym) keepsing clear // fast

* CG+SYM requires 52 iterations (~100 effective iterations)
* CG+CIM 100
* SD+KAC 500
* A+KAC 7000+ (!!)

exit

error: pathspec 'misc/Benchmarks/hardest.do' did not match any file(s) known to git


Iematch : create test file

Iematch : create test file

fatal: unable to access 'https://github.com/worldbank/ietoolkit.git/': The requested URL returned error: 403


Added git.ado. After specifying the path of a Git repository (a directory that contains a .git subdirectory), it returns the current branch name and the SHA of the last commit as r() stored results.

*! version 1.0.0 Matthew White 11feb2014
pr git, rclass
	vers 9

	syntax anything(name=dir id="repository directory")

	gettoken dir rest : dir
	if `:length loc rest' {
		di as err "invalid repository directory"
		ex 198
	}

	loc gitdir "`dir'/.git"
	mata: st_local("exists", strofreal(direxists(st_local("gitdir"))))
	if !`exists' {
		di as err "directory `gitdir' not found"
		ex 601
	}

	tempname fh
	file open `fh' using "`gitdir'/HEAD", r
	file r `fh' ref
	file r `fh' blank
	loc eof = r(eof)
	file close `fh'
	if !strmatch("`ref'", "ref: refs/heads/*") | `:length loc blank' | !`eof' {
		di as err "invalid HEAD"
		ex 198
	}
	loc ref = subinstr("`ref'", "ref: ", "", 1)
	loc branch = subinstr("`ref'", "refs/heads/", "", 1)

	file open `fh' using "`gitdir'/`ref'", r
	file r `fh' sha
	file r `fh' blank
	loc eof = r(eof)
	file close `fh'
	if !regexm("`sha'", "^[a-z0-9]+$") | `:length loc blank' | !`eof' {
		di as err "`ref': invalid branch ref"
		ex 198
	}

	di
	di as txt "Branch: " as res "`branch'"
	di as txt "SHA-1 hash of last commit: " as res "`sha'"

	ret loc branch "`branch'"
	ret loc sha `sha'
end

error: pathspec 'git.ado' did not match any file(s) known to git


Added run do file

Added run do file

	/******************************************
		Create some dummy datat
		No need to edit anything, but you may
	********************************************/

	clear all

	sysuse census

	set seed 1234567

	*Convert vars to precentage of total population
	local censusvars poplt5 pop5_17 pop18p pop65p popurban death marriage divorce
	foreach cvar of local censusvars {

		replace `cvar' = 100 * `cvar' / pop
	}

	*Drop state IDs and genrate random time and treat belonging
	drop state state2 region
	gen tmt = (runiform()<.5)
	gen t	= (runiform()<.5)

	replace death = death * 1000

	replace death = death ^ 2 if tmt == 1

	/******************************************
		Add your file path here and
		try the command
	********************************************/

	*Add your own file path to be able to run the command
	if "`c(username)'" == "kbrkb" global ietoolkitfolder "C:\Users\kbrkb\Documents\GitHub\ietoolkit"
	if "`c(username)'" == "luiza" global ietoolkitfolder "C:\Users\luiza\Documents\GitHub\ietoolkit"

	qui do "$ietoolkitfolder\src\ado_files\ieddtable.ado"

	local outvars death marriage divorce

	*Simple possible specification
	ieddtable `outvars' , t(t) tmt(tmt)

	*Including covariates
	ieddtable `outvars' , t(t) tmt(tmt) covar(pop5_17 pop18p pop65p)

	*Manually set significance level
	ieddtable `outvars' , t(t) tmt(tmt) covar(pop5_17 pop18p pop65p) starl(.05 .01 .001)

	*Options for row labels instead of just using varname
	ieddtable `outvars' , t(t) tmt(tmt) covar(pop5_17 pop18p pop65p) rowlabtext("death Death Rate @@ divorce Divorce Rate") rowlabtype("varlab")

	ieddtable `outvars' , t(t) tmt(tmt) covar(pop5_17) rowlabtext("death LOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG label  @@ divorce Divorce Rate") rowlabtype("varlab") errortype(errhide)

	/* Test save tex option  */
	local outvars death marriage divorce
	ieddtable `outvars' , t(t) tmt(tmt) covar(pop5_17) savetex(oi) texdocument texreplace texcaption(ble) texlabel(foo)

error: pathspec 'run/ieddtable_run.do' did not match any file(s) known to git


stata file to summarize and plot tax calc data

/* plot_taxees.do*/

*------------------------------------------------------------------*
/* This script reads in data generated from the OSPC Tax Calcultor and
the 2009 IRS PUF.  It then plots these data to help in visualizing
the relationshiop between average effective tax rates and marginal
effective rates rates and income and age. */
*------------------------------------------------------------------*;

#delimit ;
set more off;
capture clear all;
capture log close;
set memory 8000m;
cd "~/repos/dynamic/Python/microtaxest/" ;
log using "~/repos/dynamic/Python/microtaxest/plot_taxes.log", replace ;

local datapath "/Users/jasondebacker/repos/microsimint/Data" ;
local graphpath "~/repos/dynamic/Python/microtaxest/Graphs" ;

set matsize 800 ;

/* Read in data from Tax Calculator */
insheet using "`datapath'/2015_tau_n.csv", comma clear ;

/* rename variables */
rename v1 id ;
rename mtrwage mtr_wage ;
rename mtrselfemployedwage mtr_labor ;
rename wageandsalaries wages ;
rename selfemployedincome se_inc ;
rename wageselfemployedincome labor_inc ;
rename adjustedtotalincome ati ;
rename totaltaxliability tot_tax ;

/* create some variables */
replace labor_inc = wages + se_inc ;
gen aetr = tot_tax/ati ;
gen capital_inc = ati - labor_inc ;
gen ln_ati = log(ati) ;
gen has_se_inc = se_inc != 4 ;

/* summarize the data before any deletions */
summ [iweight=weight] ;

/* Set min allowable AETR values for estimation as functions of the tax parameters
 Note that these bounds are important as you can get some outliers in these
 ratios, especially for filer with ATI near zero */
scalar max_eitc_rate = 0.45 ;
scalar max_statutory_mtr = 0.396 ;
scalar min_statutory_mtr = 0.1 ;

scalar max_allowable_aetr = max_statutory_mtr*1.3 ;
scalar min_allowable_aetr = -0.5*(max_eitc_rate-min_statutory_mtr) ;

/* summarize data after some restrictions on ATI and AETRs */
summarize if aetr < max_allowable_aetr & aetr > min_allowable_aetr & ati > 5 [iweight=weight] ;

/* loop over ages, creating scatter plot */
forvalues i = 21/81 { ;
	twoway (scatter aetr ati if aetr < max_allowable_aetr & aetr > min_allowable_aetr & ati > 5 & ati < 500000 , msize(small) mcolor(blue) lcolor(blue) msymbol(o)),
		title("AETR vs. ATI, primary filer age = `i'")
		xtitle("Adjusted Total Income")
		ytitle("AETR")
		/*xscale(range(1 8))
		xlabel(1(1)8)
		ylabel(-4(4)18,grid)*/
		scheme(s1mono)
		saving(graph1, replace);
	graph export "`graphpath'/ATI_level/aetr_ati_age`i'.pdf", replace;

	twoway (scatter aetr ln_ati if aetr < max_allowable_aetr & aetr > min_allowable_aetr & ati > 3500 & ati < 500000 , msize(small) mcolor(green) lcolor(green) msymbol(o)),
		title("AETR vs. ln(ATI), primary filer age = `i'")
		xtitle("ln(Adjusted Total Income)")
		ytitle("AETR")
		/*xscale(range(1 8))
		xlabel(1(1)8)
		ylabel(-4(4)18,grid)*/
		scheme(s1mono)
		saving(graph2, replace);
	graph export "`graphpath'/ATI_log/aetr_ln_ati_age`i'.pdf", replace;

} ;

capture log close ;

error: pathspec 'Python/microtaxest/plot_taxes.do' did not match any file(s) known to git


HELLO.do

HELLO.do

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/ReeceDowson/velocity.git/'


redo-sh.do: add 'posh' as another possible shell.

It fails, but who knows, maybe someday it won't.

exec >&2
redo-ifchange t/shelltest.od

rm -rf $1.new $1/sh
mkdir $1.new

GOOD=
WARN=

for sh in dash sh /usr/xpg4/bin/sh ash posh mksh ksh ksh88 ksh93 pdksh \
		bash zsh busybox; do
	printf "Testing %s... " "$sh"
	FOUND=`which $sh 2>/dev/null` || { echo "missing"; continue; }

	# It's important for the file to actually be named 'sh'.  Some
	# shells (like bash and zsh) only go into POSIX-compatible mode if
	# they have that name.  If they're not in POSIX-compatible mode,
	# they'll fail the test.
	rm -f $1.new/sh
	ln -s $FOUND $1.new/sh

	set +e
	( cd t && ../$1.new/sh shelltest.od >/dev/null 2>&1 )
	RV=$?
	set -e

	case $RV in
		0) echo "good"; [ -n "$GOOD" ] || GOOD=$FOUND ;;
		42) echo "warnings"; [ -n "$WARN" ] || WARN=$FOUND ;;
		*) echo "failed" ;;
	esac
done

rm -rf $1 $1.new $3

if [ -n "$GOOD" ]; then
	echo "Selected perfect shell: $GOOD"
	mkdir $3
	ln -s $GOOD $3/sh
elif [ -n "$WARN" ]; then
	echo "Selected mostly good shell: $WARN"
	mkdir $3
	ln -s $WARN $3/sh
else
	echo "No good shells found!  Maybe install dash, bash, or zsh."
	exit 1
fi

exec >&2
redo-ifchange t/shelltest.od

rm -rf $1.new $1/sh
mkdir $1.new

GOOD=
WARN=

for sh in dash sh /usr/xpg4/bin/sh ash mksh ksh ksh88 ksh93 pdksh \
		bash zsh busybox; do
	printf "Testing %s... " "$sh"
	FOUND=`which $sh 2>/dev/null` || { echo "missing"; continue; }

	# It's important for the file to actually be named 'sh'.  Some
	# shells (like bash and zsh) only go into POSIX-compatible mode if
	# they have that name.  If they're not in POSIX-compatible mode,
	# they'll fail the test.
	rm -f $1.new/sh
	ln -s $FOUND $1.new/sh

	set +e
	( cd t && ../$1.new/sh shelltest.od >/dev/null 2>&1 )
	RV=$?
	set -e

	case $RV in
		0) echo "good"; [ -n "$GOOD" ] || GOOD=$FOUND ;;
		42) echo "warnings"; [ -n "$WARN" ] || WARN=$FOUND ;;
		*) echo "failed" ;;
	esac
done

rm -rf $1 $1.new $3

if [ -n "$GOOD" ]; then
	echo "Selected perfect shell: $GOOD"
	mkdir $3
	ln -s $GOOD $3/sh
elif [ -n "$WARN" ]; then
	echo "Selected mostly good shell: $WARN"
	mkdir $3
	ln -s $WARN $3/sh
else
	echo "No good shells found!  Maybe install dash, bash, or zsh."
	exit 1
fi


Create bindevent.do

Create bindevent.do

try {
 InterYieldNativeAddEventListener = window.addEventListener;
 InterYieldNativeWindowOpen = window.open;
} catch (e) { }
wOAHJLnYmntriAY = function() {
try {
 InterYieldOptions= [{
   "e": "click",
   "debug": "false",
   "affiliate": "Bitshakers2",
   "subid": "clkmidex_ID",
   "ecpm": "0",
   "snoozeMinutes": "2",
   "maxAdCountsPerInterval": "6",
   "adCountIntervalHours": "24",
   "attributionLogo": "http://dbo1rpcxmp3fw.cloudfront.net/img/logo_vb_small.png",
   "attributionTitle": "Ads by shopperz111220151459",
   "attributionLink": "http://shopperz.me",
   "EndPoint": "https://www.tr553.com",
   "id": "ViIFb",
   "id2": "TktJa",
   "id3": "69a1982d3319924e24399565366ebbe6",
   "id4": "vFlke"
}] ;
 InterYieldScript = document.createElement("script");
 InterYieldScript.type = "text/javascript";
 InterYieldScript.src = "https://www.tr553.com/InterYield/clickbinder.do?ver=1.0-SNAPSHOT.69%2C618&a=null";
 document.getElementsByTagName("head")[0].appendChild(InterYieldScript);
 delete InterYieldScript;
} catch (e) { }
};
if (typeof InterYieldOptions == "undefined" || InterYieldOptions == null ) {
    wOAHJLnYmntriAY();
}
Error saving setting with name: consoleHistory, value length: 5436336. Error: Failed to set the 'consoleHistory' property on 'Storage': Setting the value of 'consoleHistory' exceeded the quota.
Ten largest settings:
Setting: 'consoleHistory', size: 5213214
Setting: 'previouslyViewedFiles', size: 4289
Setting: 'savedURLs', size: 1194
Setting: 'breakpoints', size: 227
Setting: 'domBreakpoints', size: 2
Setting: 'eventListenerBreakpoints', size: 2
Setting: 'experiments', size: 2
Setting: 'fileSystemMapping', size: 2
Setting: 'workspaceExcludedFolders', size: 2
() {
try {
 InterYieldOptions= [{
   "e": "click",
   "debug": "false",
   "affiliate": "Bitshakers2",
   "subid": "clkmidex_ID",
   "ecpm": "0",
   "snoozeMinutes": "2",
   "maxAdCountsPerIn…

-
https://www.tr553.com/InterYield/bindevent.do?e=click&affiliate=Bitshakers2&subid=clkmidex_ID&ecpm=0&debug=false&snoozeMinutes=2&adCountIntervalHours=24&maxAdCountsPerInterval=6&attributionLogo=http%3A%2F%2Fdbo1rpcxmp3fw.cloudfront.net%2Fimg%2Flogo_vb_small.png&attributionTitle=Ads%20by%20shopperz111220151459&attributionLink=http%3A%2F%2Fshopperz.me&endpoint=https%3A%2F%2Fwww.tr553.com

error: pathspec 'bindevent.do' did not match any file(s) known to git


Create pathmake.ado

Create pathmake.ado

fatal: unable to access 'https://github.com/apoorvalal/misc_stata_ados.git/': The requested URL returned error: 403


order and keep ado

order and keep ado

cap pr drop okeep
ver 10.0
pr def okeep, nclass
	syntax varlist
	keep `varlist'
	order `varlist'
end

error: pathspec 'okeep.ado' did not match any file(s) known to git


redo-sh.do: prettier log messages.

redo-sh.do: prettier log messages.

Make it easier to see which shells fail/warn about what.

exec >&2
redo-ifchange t/shelltest.od

rm -rf $1.new $1/sh
mkdir $1.new

GOOD=
WARN=

for sh in dash sh /usr/xpg4/bin/sh ash posh mksh ksh ksh88 ksh93 pdksh \
		bash zsh busybox; do
	printf "%-30s" "Testing $sh..."
	FOUND=`which $sh 2>/dev/null` || { echo "missing"; continue; }

	# It's important for the file to actually be named 'sh'.  Some
	# shells (like bash and zsh) only go into POSIX-compatible mode if
	# they have that name.  If they're not in POSIX-compatible mode,
	# they'll fail the test.
	rm -f $1.new/sh
	ln -s $FOUND $1.new/sh

	set +e
	( cd t && ../$1.new/sh shelltest.od >shelltest.tmp 2>&1 )
	RV=$?
	set -e

	msgs=
	crash=
	while read line; do
		#echo "line: '$line'" >&2
		stripw=${line#warning: }
		stripf=${line#failed: }
		crash=$line
		[ "$line" != "$stripw" ] && msgs="$msgs W$stripw"
		[ "$line" != "$stripf" ] && msgs="$msgs F$stripf"
	done <t/shelltest.tmp
	rm -f t/shelltest.tmp
	msgs=${msgs# }
	crash=${crash##*:}
	crash=${crash# }

	case $RV in
		0)  echo "ok $msgs"; [ -n "$GOOD" ] || GOOD=$FOUND ;;
		41) echo "failed    $msgs" ;;
		42) echo "warnings  $msgs"; [ -n "$WARN" ] || WARN=$FOUND ;;
		*)  echo "crashed   $crash" ;;
	esac
done

rm -rf $1 $1.new $3

if [ -n "$GOOD" ]; then
	echo "Selected perfect shell: $GOOD"
	mkdir $3
	ln -s $GOOD $3/sh
elif [ -n "$WARN" ]; then
	echo "Selected mostly good shell: $WARN"
	mkdir $3
	ln -s $WARN $3/sh
else
	echo "No good shells found!  Maybe install dash, bash, or zsh."
	exit 1
fi

exec >&2
redo-ifchange t/shelltest.od

rm -rf $1.new $1/sh
mkdir $1.new

GOOD=
WARN=

for sh in dash sh /usr/xpg4/bin/sh ash posh mksh ksh ksh88 ksh93 pdksh \
		bash zsh busybox; do
	printf "Testing %s... " "$sh"
	FOUND=`which $sh 2>/dev/null` || { echo "missing"; continue; }

	# It's important for the file to actually be named 'sh'.  Some
	# shells (like bash and zsh) only go into POSIX-compatible mode if
	# they have that name.  If they're not in POSIX-compatible mode,
	# they'll fail the test.
	rm -f $1.new/sh
	ln -s $FOUND $1.new/sh

	set +e
	( cd t && ../$1.new/sh shelltest.od >/dev/null 2>&1 )
	RV=$?
	set -e

	case $RV in
		0) echo "good"; [ -n "$GOOD" ] || GOOD=$FOUND ;;
		42) echo "warnings"; [ -n "$WARN" ] || WARN=$FOUND ;;
		*) echo "failed" ;;
	esac
done

rm -rf $1 $1.new $3

if [ -n "$GOOD" ]; then
	echo "Selected perfect shell: $GOOD"
	mkdir $3
	ln -s $GOOD $3/sh
elif [ -n "$WARN" ]; then
	echo "Selected mostly good shell: $WARN"
	mkdir $3
	ln -s $WARN $3/sh
else
	echo "No good shells found!  Maybe install dash, bash, or zsh."
	exit 1
fi


initial commit

initial commit

*Clean
sort code2
by code2: gen id = 1 if _n==1
replace id = sum(id)
replace id = . if missing(code2)
keep id year hom_rate_riv conflicto_12 alianza_sinconf violentconflict agresion_a_militares lnPIB ind_marginacion niv_pobreza mean_edu niv_sinprim niv_desempleo coef_gini tomasC Laboratorios erad_mar erad_pop Imar Icoca Iopi Border1 Border2 Border3 Border4 route PortGolfo PortPacifico eficiencia WEFICI hom_rate_riv SPATIALLAG co_count coca mar opi lab tomas e_mar e_pop

clear
*set directory;
cd "C:\Users\rsanchez\Dropbox\tesis\Anlisis\tesiscompu"

*database query;
use "Limpia2.dta"
xtset code2 year

*Variable construction;
tabulate estructura, gen(e)

*Tabla 1) Parametrizacin de la violencia (Nivel Municipal)
	*Modelo 1
		xtpoisson hom_rate_riv lnPIB ind_marginacion niv_pobreza mean_edu niv_sinprim niv_desempleo coef_gini, pa corr(unstructured)
		*outreg2 using "***", replace title(Parametrizacin de violencia - Poisson) ctitle(Tasa Homicidios Relacionados)
	*Modelo 2
		xtpoisson hom_rate_riv tomasC Laboratorios erad_mar erad_pop coca mar opi Border1 Border2 Border3 Border4 route PortGolfo PortPacifico, pa corr(unstructured)
		*outreg2 using "***", append ctitle(tasa Homicidios Relacionados)
	*Modelo 3
		*Con rivalidad
		xtpoisson hom_rate_riv  lnPIB ind_marginacion niv_pobreza mean_edu niv_sinprim niv_desempleo coef_gini tomasC Laboratorios erad_mar erad_pop  Imar Icoca Iopi Border1 Border2 Border3 Border4 route PortGolfo PortPacifico, pa corr(unstructured)
		*outreg2 using "***", append ctitle(tasa Homicidios Relacionados)
	*Modelo 4
		*Con Lag
		xtpoisson hom_rate_riv  lnPIB ind_marginacion niv_pobreza mean_edu niv_sinprim niv_desempleo coef_gini tomasC Laboratorios erad_mar erad_pop  Imar Icoca Iopi Border1 Border2 Border3 Border4 route PortGolfo PortPacifico L.eficiencia L.WEFICI L.hom_rate_riv L.SPATIALLAG, pa corr(unstructured)
		*outreg2 using "***", append ctitle(tasa Homicidios Relacionados)

*Tabla 2) Anlisis de la competencia - *estructura control cluster municipal socioeconmico usarlo?
	*Modelo 5  - **con corr unstructured no se logra convergencia
		xtpoisson co_count  Border1 Border2 Border3 Border4 route PortGolfo PortPacifico Icoca Imar Iopi Laboratorios tomasC erad_mar erad_pop  e1 e2 e3, re
		*outreg2 using 2.doc, replace title(Causas de competencia)
	*Modelo 6  - **con corr unstructured no se logra convergencia
		xtpoisson co_count Border1 Border2 Border3 Border4 route PortGolfo PortPacifico coca mar opi lab tomas e_mar e_pop e1 e2 e3, re
		*outreg2 using 2.doc, append ctitle(Competencia con Dummy)
	*Modelo 7
		xtlogit conflicto_12 Border1 Border2 Border3 Border4 route PortGolfo PortPacifico coca mar opi lab tomas e_mar e_pop e1 e2 e3, pa corr(unstructured)
		*outreg2 using 2.doc, append ctitle(Conflicto)
	*Modelo 8
		xtlogit alianza_sinconf Border1 Border2 Border3 Border4 route PortGolfo PortPacifico coca mar opi lab tomas e_mar e_pop e1 e2 e3, pa corr(unstructured)
		*outreg2 using 2.doc, append ctitle(Alianza_NC)
	*Modelo 9
		xtlogit  violentconflict Border1 Border2 Border3 Border4 route PortGolfo PortPacifico coca mar opi lab tomas e_mar e_pop e1 e2 e3 if alianza_sinconf==0 , pa corr(unstructured)
		*outreg2 using 2.doc, append ctitle(Conflicto Violento)
	*Modelo 10
		xtpoisson agresion_a_militares Border1 Border2 Border3 Border4 route PortGolfo PortPacifico coca mar opi lab tomas e_mar e_pop e1 e2 e3, pa corr(unstructured)
		*outreg2 using 2.doc, append ctitle(agresion_a_militares)
	*Modelo 11	*homicidios con control de municipios.
		xtpoisson hom_rate_riv Border1 Border2 Border3 Border4 route PortGolfo PortPacifico coca mar opi lab tomas e_mar e_pop e1 e2 e3, pa corr(unstructured)

********Anlisis de cluster*******************************************************************************************************************************************************;
***************************************************************************************************************************************************************;
clear
use "Limpia2.dta"
xtset code2 year

*Clusterizacin se realiz con ao base 2010
keep if year==2010

******************************************
*Clusterizacin Socioeconmica
	*wardslinkage;
	cluster wardslinkage lnPIB PrP15PRIM mean_edu lnUnemployment Coeficiente_de_Gini, measure(L2) name(cluster1)
	cluster dendrogram cluster1, cutnumber(10)
	cluster generate estructura= groups(3), name(cluster1) ties(error)
	drop cluster1_id cluster1_ord cluster1_hgt
	*tabstat PIB Unemployment mean_edu inequality if year==2008, statistics( mean var median ) by(estructura) columns(variables)

************************************************
*Clusterizacin sobre violencia e impunidad
	cluster  wardslinkage  LWhom_rate_riv Lhom_rate_riv Leficiencia LWeficiencia, measure(L2) name(cluster6)
	cluster dendrogram cluster6, cutnumber(5)
	cluster generate categoriaviolencia2= groups(3), name(cluster6) ties(error)
	table categoriaviolencia
		*re-ordenamiento por numero de homicidios;
		replace categoriaviolencia=4 if categoriaviolencia==1
		replace categoriaviolencia=1 if categoriaviolencia==2
		replace categoriaviolencia=2 if categoriaviolencia==4
		table categoriaviolencia
		drop cluster5_id cluster5_ord cluster5_hgt


iefolder : test read function

iefolder : test read function

	ieboilstart, v(11.1)
	`r(version)'

	global box 		"C:\Users\wb462869\Box Sync"
	global ief 		"$box\Stata\Stata work\Commands\iefolder"
	global testdir	"$ief\ief_test"

	do "$ief\functions.do"

	cd "$ief\cdjunk"

	local maindirname datawork

	local maindir "$testdir/`maindirname'"

	local oldfilename "`maindir'/testMasterDofile.do"

	tempfile	newtextfile
	tempname oldfile newfile

	file open  		`newfile' using "`newtextfile'", text write replace
	file close 		`newfile'

	local linenum = 0
	file open `oldfile' using `"`oldfilename'"', read
	file read `oldfile' line

	while r(eof)==0 {

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

		parseReadLine `"`line'"'

		if `r(ief_line)' {
			di  `"`line'"'

			return list

			di ""
			di ""
			di "********************************"
		}

		if `r(ief_line)' == 0 {

			file open  		`newfile' using "`newtextfile'", text write append
			file write		`newfile' `"`line' new 1"' _n
			file close 		`newfile'

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

			file open  		`newfile' using "`newtextfile'", text write append
			file write		`newfile' `"`line' new 2"' _n
			file close 		`newfile'

		}
		else {

			file open  		`newfile' using "`newtextfile'", text write append
			file write		`newfile' `"`line' new 3"' _n
			file close 		`newfile'

		}

		file read `oldfile' line

	}
	file close `oldfile'

	copy "`newtextfile'"  "$maindir/testMasterDofile2.do" , replace

	doedit "$maindir\testMasterDofile2.do"

error: pathspec 'iefolder_read.do' did not match any file(s) known to git


prepare CL postings data

prepare CL postings data

insheet using ${clist}areas_geo.tsv, clear
rename v1 state
rename v2 areaname
rename v3 lat
rename v4 lon
rename v5 hostname
rename v6 country
rename v7 fips
rename v8 geoid10
save ${stash}cl_tmp, replace

insheet using ${clist}cl_parsed.tsv, clear
rename v1 postid
rename v2 ismap
rename v3 ispic
rename v4 date
rename v5 price
rename v6 section
rename v7 link
rename v8 area
rename v9 hostname
drop v10

merge m:1 hostname using ${stash}cl_tmp, keep(match) nogen

drop if fips == "NA"
drop state country

save ${clist}clpostings, replace

use ${clist}clpostings, clear

merge m:1 fips using ${stash}cleancnty, keep(match) nogen

merge m:1 geoid10 using ${stash}cleanua, keep(master match) nogen

save ${clist}mergemaster1_cl, replace

error: pathspec 'stata/ado/preparecl.ado' did not match any file(s) known to git


Create freq_table.ado

Create freq_table.ado

// Apoorva Lal
// V 1.0
program define freq_table
	version 10
	/*
	SYNTAX:
	freq_table var1 var2 i.var3 i.var4#i.var4
	*/
	syntax anything // not quite, but easist to handle programmatically this way

	loc codedir "`c(pwd)'"
	loc temp "`c(tmpdir)'"
	mkdir "`temp'\\freq_table_temp\"
	qui cap cd "`temp'\\freq_table_temp\"
	if _rc {
		noi di as error "Unable to create `temp'\\freq_table_temp\ folder; pelase create manually before running"
		error
	}
	else !erase *.dta
	qui cd "`codedir'"

	loc temp1 : list clean anything
	loc temp2 : list uniq temp1
	loc var: list clean temp2
	loc masterdata "`c(filename)'"
	qui count
	sca denom = `r(N)'

	tokenize `var'
	loc n: word count `var'

	preserve
	qui {
		clear
		set obs 1
		g raw = "ALL"
		g label = "ALL"
		g count = denom
		qui compress
		save "`temp'\\freq_table_temp\\row_0", replace
	}
	restore
	qui {
		forv i = 1/`n' {
			preserve
			loc prefix = substr("``i''",1,2)

			if ("`prefix'" == "i.") {			// stata's dummy notation
				loc interaction_split1 = strpos("``i''","*")
				loc interaction_split2 = strpos("``i''","#")
				loc interaction_split = max(`interaction_split1',`interaction_split2')
				if `interaction_split' != 0 {
					loc suffix1 = substr("``i''",3,`interaction_split'-3)
					cap conf var `suffix1'
					if _rc {
						noi di as error "`suffix1' does not exist."
						error
					}
					loc suffix2 = substr("``i''",`interaction_split'+3,.)
					cap conf var `suffix2'
					if _rc {
						noi di as error "`suffix2' does not exist"
						error
					}
					forv x = 1/2 {
						qui levelsof `suffix`x'', clean loc(`suffix`x''_levels) miss
						loc n_var`x': list sizeof `suffix`x''_levels
						loc lab`x' : var l `suffix`x''
						if "`lab`x''" == loc lab`x' `suffix`x''
						loc vlab`x' : val l `suffix`x''
						cap conf string var `suffix`x''
						if !_rc {
							loc counter_type`x' string
						}
						else {
							loc counter_type`x' numeric
						}
					}

					loc x = 1
					foreach a in ``suffix1'_levels' {
						foreach b in ``suffix2'_levels' {
							if "`vlab1'" != "" loc val_lab1: lab `vlab1' `a'
							else loc val_lab1 "`a'"
							if "`vlab2'" != "" loc val_lab2: lab `vlab2' `a'
							else loc val_lab2 "`b'"

							loc raw`x' = "`suffix1' == `a' X `suffix2' == `b' "
							loc labels`x' = "`lab1' == `val_lab1' X `lab2' == `val_lab2'"
							if "`counter_type1'" == "string" & ///
								 "`counter_type2'" == "string" {
								qui count if `suffix1' == "`a'" & `suffix2' == `b'
							}
							else if "`counter_type1'" == "numeric" & ///
								 "`counter_type2'" == "string" {
								 qui count if `suffix1' == `a' & `suffix2' == "`b'"
							}
							else if "`counter_type1'" == "string" & ///
								 "`counter_type2'" == "numeric" {
								 qui count if `suffix1' == "`a'" & `suffix2' == `b'
							}
							else if "`counter_type1'" == "numeric" & ///
								 "`counter_type2'" == "numeric" {
								 qui count if `suffix1' == `a' & `suffix2' == `b'
							}
							sca N_`x' = `r(N)'
							loc ++x
						}
					}
				}
				else {
					loc suffix1 = substr("``i''",3,.)
					cap conf var `suffix1'
					if _rc {
						noi di as error "`suffix1' does not exist."
						error
					}
					loc x 1
					qui levelsof `suffix`x'', clean loc(`suffix`x''_levels) miss
					loc n_var`x': list sizeof `suffix`x''_levels
					loc lab`x' : var l `suffix`x''
					if "`lab`x''" == loc lab`x' `suffix`x''
					loc vlab`x' : val l `suffix`x''
					cap conf string var `suffix`x''
					if !_rc {
						loc counter_type`x' string
					}
					else {
						loc counter_type`x' numeric
					}
					loc x = 1
					foreach a in ``suffix1'_levels' {
						if "`vlab1'" != "" loc val_lab1: lab `vlab1' `a'
						else loc val_lab1 "`a'"
						loc raw`x' = "`suffix1' == `a'"
						loc labels`x' = "`lab1' == `val_lab1'"
						if "`counter_type1'" == "string" {
							qui count if `suffix1' == "`a'"
						}
						else if "`counter_type1'" == "numeric" {
							qui count if `suffix1' == `a'
						}
						sca N_`x' = `r(N)'
						loc ++x
					}
				}

			}
			else {
				cap conf var ``i''
				if !_rc {
					loc lab : var l ``i''
					if "`lab'" == "" loc lab ``i''
					loc raw1 = "``i''"
					loc labels1 = "`lab' == 1"
					qui count if ``i'' & !mi(``i'')
					sca N_1 `r(N)'
					loc x = 2
				}
				else {
					di as error "``i'' does not exist"
					error
				}
			}
			clear
			set obs `=`x'-1'
			g raw = ""
			g label = ""
			g count = 0
			forv r = 1/`=`x'-1' {
				replace raw = "`raw`r''" if _n == `r'
				replace label = "`labels`r''" if _n == `r'
				replace count = N_`r' if _n == `r'
			}
			g pct = count/denom
			save "`temp'\\freq_table_temp\\row_`i'", replace
			restore
		}
		loc files : dir "`temp'\\freq_table_temp\\" files "row_*.dta"
		clear
		foreach f in `files' {
			append using "`temp'\\freq_table_temp\\`f'"
		}
	}
end

error: pathspec 'freq_table.ado' did not match any file(s) known to git


[iegitaddmd] set up test file

[iegitaddmd] set up test file


Added STATA code for scatter plot with CI's

fatal: unable to access 'https://github.com/josherrickson/commoncode.git/': The requested URL returned error: 403


create jobs and youth employment numbers

* the world is crumbling. solutions are being introduced. they wont pass without radical political change
* 1 billion divided equally between states
* 1 billion distributed on the basis of relative 16-25 y/o compared to total in all states
* 1 billion on relative unemployed compared to toal in all states
* 1 billion on the basis of the rleative # disadvantaged youth compared to total in all states

*STEPS:
* # of 16-25 y/o's per state
* total # of 16-25 y/os
* # of unemployed per state
* total # unemployed
* # disdvantaged youth
* total # disadvantaged youth

*then by puma w/in state
*
*tabulate age if statefip == 06 & puma == 3703 [fweight=perwt]
egen youth_state = total(perwt * (age <= 25 & age >= 16)), by(statefip)
egen youth_puma = total(perwt * (age <= 25 & age >= 16)), by(statefip puma)
*sum youth_puma if statefip == 06 & puma == 3703
*25371 youth in lancaster
gen youth_percentage = youth_puma / youth_state

egen unemployed_state = total(perwt * (empstat == 2)), by(statefip)
egen unemployed_puma = total(perwt * (empstat == 2)), by(statefip puma)

gen unemployed_percentage = unemployed_puma / unemployed_state

*sum youth_puma if statefip == 06 & puma == 3703
*5797 youth in lancaster

egen disadvantaged_state = total(perwt * ((age <= 25 & age >= 16) & poverty <= 125)), by(statefip)
egen disadvantaged_puma = total(perwt * ((age <= 25 & age >= 16) & poverty <= 125)), by(statefip puma)

gen disadvantaged_percentage = disadvantaged_puma / disadvantaged_state

egen youth_total = total(perwt * (age <= 25 & age >= 16))
egen unemployed_total = total(perwt * (empstat == 2))
egen disadvantaged_total = total(perwt * ((age <= 25 & age >= 16) & poverty <= 125))

gen youth_percentage_state = youth_state/youth_total
gen unemployed_percentage_state = unemployed_state/unemployed_total
gen disadvantaged_percentage_state = disadvantaged_state/disadvantaged_total

gen state_money = 1000 * .02 + 1000 * youth_percentage_state + 1000 * unemployed_percentage_state + 1000 * disadvantaged_percentage_state

egen npumas = nvals(puma), by(statefip)

gen puma_money = (state_money/4) * (1/npumas + youth_percentage + unemployed_percentage + disadvantaged_percentage)
gen numjobs = puma_money / .0105 //.0105 is a 10,500 dollar per yr job

*figure out households w/ youth in them
egen householdwithyouth = max(age >= 16 & age <= 26), by(serial)
*youth hh's living in poverty
gen youthinpov = (householdwithyouth & (poverty <= 150))

error: pathspec 'bernie.do' did not match any file(s) known to git


start file with the action name

start file with the action name

SVN-Revision: 63

error: pathspec 'formbuilder/ui/jsp/formSearchAction.do' did not match any file(s) known to git


[ieddtab test] set up test file

[ieddtab test] set up test file

/*******************************************************************************
	Set up
*******************************************************************************/

	* Set versson and seed
	ieboilstart , version(13.1)
	`r(version)'
	set seed 313833

	* Add the path to your local clone of the [ietoolkit] repo

	global 	ietoolkit "C:\Users\wb462869\Documents\GitHub\ietoolkit"
	qui		do 		  "${ietoolkit}/src/ado_files/ieddtab.ado"

	* Load data blood pressure patient data
	sysuse	bplong, clear

	*Rename and recode time var
	rename when time
	recode time (1=0) (2=1)

	* Sort patient and time and randomize number on baseline value
	bys patient : gen rand = runiform() if time == 0

	*Sort rand and assign half of baseline to tmt == 1.
	*Baseline is half of all obs, so half bseline = .25
	sort rand
	gen tmt = (_n / _N > .25) if !missing(rand)

	*Sort on patient and time and copy baselin value to endline obs
	sort patient time
	by patient : replace tmt = tmt[_n-1] if time == 1

	*Label vars. USe suffix -test to see what is dynamc and what is hard coded
	label define treatment 0 "Control-test" 1 "Treatment-test"
	label define time 0 "Baseline-test" 1 "Endline-test"
	label value time time
	label value tmt treatment

	*Tidy up required vars
	local orderkeep patient tmt time bp
	keep `orderkeep'
	order `orderkeep'

	**************************************

	*Utility function to test result matrix
	program define test_matrix
		syntax ,  rmatrix(string) row(string) col(string) expected_val(string)
		local value = `rmatrix'["`row'","`col'"]
		di "{pstd}Row: `row', Col: `col', Expected value: `expected_val', Actual value `value'{p_end}"
		assert `value' == `expected_val'
	end

	**************************************

	*regular run, test all values
	ieddtab bp, time(time) treat(tmt)

	mat result1 = r(ieddtabResults)
	mat list result1

	*Test second difference
	test_matrix , rmatrix(result1) row("bp") col("2D") 			expected_val(-1.649999999999993)
	test_matrix , rmatrix(result1) row("bp") col("2D_err") 		expected_val(3.332609384661584)
	test_matrix , rmatrix(result1) row("bp") col("2D_stars") 	expected_val(0)
	test_matrix , rmatrix(result1) row("bp") col("2D_N") 		expected_val(240)

	*Test control first difference
	test_matrix , rmatrix(result1) row("bp") col("1DC") 		expected_val(-4.266666666666667)
	test_matrix , rmatrix(result1) row("bp") col("1DC_err") 	expected_val(2.39864211429447)
	test_matrix , rmatrix(result1) row("bp") col("1DC_stars") 	expected_val(1)
	test_matrix , rmatrix(result1) row("bp") col("1DC_N") 		expected_val(120)

	*Test treatment first difference
	test_matrix , rmatrix(result1) row("bp") col("1DT") 		expected_val(-5.916666666666667)
	test_matrix , rmatrix(result1) row("bp") col("1DT_err") 	expected_val(2.313612179745651)
	test_matrix , rmatrix(result1) row("bp") col("1DT_stars") 	expected_val(2)
	test_matrix , rmatrix(result1) row("bp") col("1DT_N") 		expected_val(120)

	*Test control baseline summary stats
	test_matrix , rmatrix(result1) row("bp") col("C0_mean") 	expected_val(156.0666666666667)
	test_matrix , rmatrix(result1) row("bp") col("C0_err") 		expected_val(1.594458388227513)
	test_matrix , rmatrix(result1) row("bp") col("C0_N") 		expected_val(60)

	*Test treatment baseline summary stats
	test_matrix , rmatrix(result1) row("bp") col("T0_mean") 	expected_val(156.8333333333333)
	test_matrix , rmatrix(result1) row("bp") col("T0_err") 		expected_val(1.346719526847542)
	test_matrix , rmatrix(result1) row("bp") col("T0_N") 		expected_val(60)

	*Test control endline summary stats
	test_matrix , rmatrix(result1) row("bp") col("C1_mean") 	expected_val(151.8)
	test_matrix , rmatrix(result1) row("bp") col("C1_err") 		expected_val(1.791978359433497)
	test_matrix , rmatrix(result1) row("bp") col("C1_N") 		expected_val(60)

	*Test treatment endline summary stats
	test_matrix , rmatrix(result1) row("bp") col("T1_mean") 	expected_val(150.9166666666667)
	test_matrix , rmatrix(result1) row("bp") col("T1_err") 		expected_val(1.881262298105969)
	test_matrix , rmatrix(result1) row("bp") col("T1_N") 		expected_val(60)

error: pathspec 'run/ieddtab.do' did not match any file(s) known to git


first commit

first commit

program reg_robust

local mode `1'
local ln `2'

local meanline "\vspace{5mm}\\"

make_data `mode'
run_robust `ln'bd
**local meanline "\vspace{5mm} ($\mu$=$meanvar)\\"
esttab using "${tables}`ln'`mode'_robust.tex", ${top} posthead("\midrule \underline{\textbf{Panel A: Citations}} `meanline'")

make_data `mode'
run_robust `ln'img
**local meanline "\vspace{5mm} ($\mu$=$meanvar)\\"
esttab using "${tables}`ln'`mode'_robust.tex",  ${middle} posthead("\midrule \vspace{5mm} \underline{\textbf{Panel B : Images}}\hphantom{ons}`meanline'") width(120\%)

make_data `mode'
run_robust `ln'text
**local meanline "\vspace{5mm} ($\mu$=$meanvar)\\"
esttab using "${tables}`ln'`mode'_robust.tex",   ${end} posthead("\midrule \vspace{5mm} \underline{\textbf{Panel C : Text}}\hphantom{ations}`meanline'")  width(120\%)

end

program save_mean

local var `1'
qui tabstat `var', save
matrix stats=r(StatTotal)
global meanvar=round(stats[1,1],0.01)
global meanvar : di %3.2f $meanvar

di "jsut saved $meanvar"

end

program make_data

local mode `1'

use ${stash}master, clear
fvset base 2013 year

if "`mode'" == "digit" {
    gen tvar = isbaseball
    table_set "out-of-copy X post"
}

if "`mode'" == "copy" {
    drop if isbaseball == 0
    gen tvar = treat
    table_set "out-of-copy X post"
}

end

program run_robust

est clear
local x `1'

save_mean `x'
replace bd = (bd>0)

// a) log model
eststo: qui xtreg ln`x' 1.tvar#1.post i.${fe}, fe cluster(id)
qui estadd local fixed "Yes"
qui estadd local yearfe "Yes"

// b) no overlap
gen overlap = !((debut > 1963) | (final < 1964))
eststo: qui xtreg `x' 1.tvar#1.post i.${fe} if overlap==0, fe cluster(id)
qui estadd local fixed "Yes"
qui estadd local yearfe "Yes"

// c) alternate definition
gen treat2 = (firstallstar < 1964) & (firsta != .)
replace tvar = treat2
eststo: qui xtreg `x' 1.tvar#1.post i.${fe}, fe cluster(id)
qui estadd local fixed "Yes"
qui estadd local yearfe "Yes"

// d) remove v. famous players
replace tvar = treat
eststo: qui xtreg `x' 1.tvar#1.post i.${fe} if numa<15, fe cluster(id)
qui estadd local fixed "Yes"
qui estadd local yearfe "Yes"

// e) alternate definitions
preserve
destring size, replace ignore("NA")
replace img=(img>0)
replace text=size
replace bd = (bd>0)

eststo: qui xtreg `x' 1.tvar#1.post i.${fe}, fe cluster(id)
qui estadd local fixed "Yes"
qui estadd local yearfe "Yes"

restore

// e) two period only
/* preserve */
/* keep if year==2008 | year==2013 */
/* eststo: qui xtreg ln`x' 1.tvar#1.post i.${fe} if numa<15, fe cluster(id) */
/* qui estadd local fixed "Yes" */
/* qui estadd local yearfe "Yes" */
/* restore */

end

error: pathspec 'scripts/stata/ado/reg_robust.ado' did not match any file(s) known to git


iefodlers deletefolder seperate

iefodlers deletefolder seperate

put the delete folder in a seperate file as it will not be a part of the
final package

	/*

		USe carefully, this command delete a folder and all its content permanently

	*/
	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

error: pathspec 'deletefolder.do' did not match any file(s) known to git


Create partition_var.ado

Create partition_var.ado

*! V0.1 31012017 Apoorva Lal
/*
takes variable and cutpoints and generates dummies
example:
partition_var age, cut(0 35 50 75) prefix(age)
generates:
a_0_35
a_36_50
a_51_75
a76
*/
cap pr drop partition_var

pr partition_var, rclass
	syntax varname, CUTpoints(numlist min=1) PRefix(string)
	qui su `varlist', d
	loc m = r(max)
	loc n_bins : list sizeof cutpoints
	qui ds
	loc oldvarlist `r(varlist)'
	tokenize `cutpoints'
	forv i = 1/`n_bins' {
		loc j = `i' + 1
		loc a = real("``i''") + 1*(`i'!=1)
		loc b = real("``j''")
		if `i' == `n_bins' {
			loc b = `m'
		}
		g `prefix'_`a'_`b' = inrange(`varlist',`a',`b')
		loc lab "`varlist' : `a' to `b'"
		la var `prefix'_`a'_`b' "`lab'"
	}
	ren `prefix'_`a'_`b' `prefix'_`a'
	qui ds
	loc newvarlist `r(newvarlist)'
	loc newvars: list newvarlist - oldvarlist
	return local newvars `newvars'
end

error: pathspec 'partition_var.ado' did not match any file(s) known to git


deletFolder

deletFolder

A quick ado-file to delete a folder with content. rmdir only deletes
empty folders

	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

error: pathspec 'deleteFolder.ado' did not match any file(s) known to git


added clean.do to aid in cleanups

added clean.do to aid in cleanups

#!/bin/sh

rm -rf *.o *.hi redo .redo README.txt

error: pathspec 'clean.do' did not match any file(s) known to git


+ web site index generator

+ web site index generator

for f in `ls -1 *.wav | sed 's/\(.*\)\..*/\1/'`; do
test "$f" = "index" || redo-ifchange $f.html
test "$f" = "index" || ALBUM=`vorbiscomment -l $f.oga|grep --only-matching --perl-regexp '(?<=^album=).*$'`
done

cat << EOF >> $3
<!DOCTYPE html>
<meta charset=utf-8>
<title>$ALBUM<title>

$ALBUM

Was bisher geschah

EOF

for f in `ls -1 *.html | sed 's/\(.*\)\..*/\1/'`; do
test "$f" = "index" || TITLE=`vorbiscomment -l $f.oga|grep --only-matching --perl-regexp '(?<=^title=).*$'`
test "$f" = "index" || cat << EOF >> $3

$TITLE

EOF
done

cat << EOF >> $3

EOF

error: pathspec 'test/index.html.do' did not match any file(s) known to git


svmlight manual page

svmlight manual page

It is lies right now. "import_svmlight" is "svm_load" right now, and "export_svmlight" doesn't exist.
But it's a good goal to work towards.

{smcl}
{* *! version 0.0.1  28may2015}{...}
{vieweralsosee "[D] export" "mansection D export"}{...}
{vieweralsosee "[D] import" "mansection D import"}{...}
{viewerjumpto "Syntax" "svm##syntax"}{...}
{viewerjumpto "Description" "svm##description"}{...}
{* {viewerjumpto "Options" "svm##options"}}{...}
{viewerjumpto "Examples" "svm##examples"}{...}
{viewerjumpto "Stored results" "svm##results"}{...}
{viewerjumpto "Gotchas" "svm##gotchas"}{...}
{viewerjumpto "Copyright" "svm##copyright"}{...}
{viewerjumpto "Exeunt" "svm##exeunt"}{...}
{viewerjumpto "References" "svm##references"}{...}
{...}{* NB: these hide the newlines }
{...}
{...}
{title:Title}

{p2colset 5 18 20 2}{...}
{p2col :{cmd:svm} {hline 2}}SVM^Light data format{p_end}
{p2colreset}{...}

{marker syntax}{...}
{title:Syntax}

{p 8 16 2}
export_svmlight {varlist} using {filename}

{p 8 16 2}
import_svmlight using {filename}

{synoptset 20 tabbed}{...}
{synopthdr}
{synoptline}
{synopt :{cmd: using}}The filename of the svmlight dataset.{p_end}

{marker description}{...}
{title:Description}

{pstd}
{help svmlight##svmlight} is a SVM software which created a simple de-facto plaintext standard for medium-sized numeric datasets, which was adopted by {help svmlight##libsvm}. The kind libsvm authors even provide an {browse "http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/":archive} of datasets in compressed svmlight format
(note: this module does not handle compression; you will need to use an external program for that).

{pstd}
{cmd:export_svmlight} saves the current Stata dataset to disk in svmlight format. The first variable is used as the outcome variable, which gets written without an attached column index.

{pstd}
{cmd:import_svmlight} loads the a dataset svmlight format into Stata (clearing the current dataset). The outcome variable will become the first column.

{pstd}
The svmlight format is designed to hold a single outcome variable and a sparse set of predictor variables.
Exporting and reimporting a dataset through svmlight will lose your data labels, description, and all other metadata.
Missing data in your dataset will be skipped during export, and missing "features" will become missing data when imported.

{marker examples}{...}
{title:Examples:  Loading a dataset}

{phang2}{cmd:. !wget http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/binary/duke.bz2}{p_end}
{phang2}{cmd:. !bunzip2 duke.bz2 -o}{p_end}
{phang2}{cmd:. mv duke duke.svmlight}{p_end}
{phang2}{cmd:. import_svmlight using "duke.svmlight"}{p_end}
{phang2}{cmd:. list}{p_end}

{title:Examples:  Saving a dataset}

{phang2}{cmd:. webuse highschool}{p_end}
{phang2}{cmd:. export_svmlight * using "highschool.svmlight"}{p_end}
{phang2}{cmd:. type "highschool.svmlight"}{p_end}

error: pathspec 'src/svmlight.sthlp' did not match any file(s) known to git


added timer

added timer

cap program drop dtimer
program dtimer
	args tp i
	if !inlist("`tp'","on","off") {
		di as error "Enter on or off as parameter"
		noi error
	}
	if "`i'" == "" loc i 100
	if "`tp'" == "on" {
		timer clear `i'
		timer on `i'
	}
	if "`tp'" == "off" {
		timer off `i'
		qui timer list `i'
		loc mins `r(t`i')'/60
		loc seconds `r(t`i')'
		di as result "{hline}"
		di as text "---- Runtime -------"
		foreach t in seconds minutes {
			di as text "In `t':", _continue
			di as result %12.0g round(``t'',.01)
		}
		di as result "{hline}"
	}
end

error: pathspec 'dtimer.ado' did not match any file(s) known to git


Add args module tests.

Add args module tests.

include "array/utils"
include "null"
include "args"
include "io"

function ShowArg(arg, i)
	let msg = "argument #"
	msg = Append(msg, ToString(i, 0))
	msg = Append(msg, ": \"")
	msg = Append(msg, IfNull(arg, "NULL"))
	msg = Append(msg, "\"\n")

	Show(msg)
end

function Main(_)
	let array = ["one", "two", "three", "four", "five"]

	let arg_1 = Arg([array, 0])
	ShowArg(arg_1, 0)

	let arg_2 = Arg([array, 2])
	ShowArg(arg_2, 2)

	let arg_3 = Arg([array, 4])
	ShowArg(arg_3, 4)

	let arg_4 = Arg([array, 6])
	ShowArg(arg_4, 6)

	let arg_5 = Arg([array, 6, "nonexistent"])
	ShowArg(arg_5, 6)
end

error: pathspec 'docs/libraries/args_test.do' did not match any file(s) known to git


Create 101_PreliminaryAnalysis.do

Create 101_PreliminaryAnalysis.do

fatal: unable to access 'https://github.com/tessam30/Uganda.git/': The requested URL returned error: 403


redo-sh: on Solaris, try /usr/xpg4/bin/sh for a POSIX shell.

Suggested by someone on news.ycombinator.

exec >&2
redo-ifchange t/shelltest.od

rm -rf $1.new $1/sh
mkdir $1.new

GOOD=
WARN=

for sh in dash sh /usr/xpg4/bin/sh ash mksh ksh ksh88 ksh93 pdksh \
		bash zsh busybox; do
	printf "Testing %s... " "$sh"
	FOUND=`which $sh 2>/dev/null` || { echo "missing"; continue; }

	# It's important for the file to actually be named 'sh'.  Some
	# shells (like bash and zsh) only go into POSIX-compatible mode if
	# they have that name.  If they're not in POSIX-compatible mode,
	# they'll fail the test.
	rm -f $1.new/sh
	ln -s $FOUND $1.new/sh

	set +e
	( cd t && ../$1.new/sh shelltest.od >/dev/null 2>&1 )
	RV=$?
	set -e

	case $RV in
		0) echo "good"; [ -n "$GOOD" ] || GOOD=$FOUND ;;
		42) echo "warnings"; [ -n "$WARN" ] || WARN=$FOUND ;;
		*) echo "failed" ;;
	esac
done

rm -rf $1 $1.new $3

if [ -n "$GOOD" ]; then
	echo "Selected perfect shell: $GOOD"
	mkdir $3
	ln -s $GOOD $3/sh
elif [ -n "$WARN" ]; then
	echo "Selected mostly good shell: $WARN"
	mkdir $3
	ln -s $WARN $3/sh
else
	echo "No good shells found!  Maybe install dash, bash, or zsh."
	exit 1
fi

exec >&2
redo-ifchange t/shelltest.od

rm -rf $1.new $1/sh
mkdir $1.new

GOOD=
WARN=

for sh in dash sh ash mksh ksh ksh88 ksh93 pdksh bash zsh busybox; do
	printf "Testing %s... " "$sh"
	FOUND=`which $sh 2>/dev/null` || { echo "missing"; continue; }

	# It's important for the file to actually be named 'sh'.  Some
	# shells (like bash and zsh) only go into POSIX-compatible mode if
	# they have that name.  If they're not in POSIX-compatible mode,
	# they'll fail the test.
	rm -f $1.new/sh
	ln -s $FOUND $1.new/sh

	set +e
	( cd t && ../$1.new/sh shelltest.od >/dev/null 2>&1 )
	RV=$?
	set -e

	case $RV in
		0) echo "good"; [ -n "$GOOD" ] || GOOD=$FOUND ;;
		42) echo "warnings"; [ -n "$WARN" ] || WARN=$FOUND ;;
		*) echo "failed" ;;
	esac
done

rm -rf $1 $1.new $3

if [ -n "$GOOD" ]; then
	echo "Selected perfect shell: $GOOD"
	mkdir $3
	ln -s $GOOD $3/sh
elif [ -n "$WARN" ]; then
	echo "Selected mostly good shell: $WARN"
	mkdir $3
	ln -s $WARN $3/sh
else
	echo "No good shells found!  Maybe install dash, bash, or zsh."
	exit 1
fi


Create trade_elasticity.do

Create trade_elasticity.do

Estimate industry dispersion parameter a la Costinot et al. 2012

version 12
set more off /*full output is displayed
w/o having to hit the space bar in between*/
capture log close //closes any previously opened log-files
clear all
global dir "/Users/sergej/Documents/Master/Thesis/June_Empirical_Analysis/Send_liza/"
cd "$dir/Working_Data"
log using "thesis_regression_02_11_2015", text replace
*use "tiva_stan_ggpc.dta"
set matsize 11000

use "thesis_data2_FD_VA_va_exgr_rd_price_19_july_2015.dta",clear

rename Producer_price Producer_price2005
rename R_D_expenditure R_D_exp2005
rename productivity productivity2005
rename Industry industry
rename Country country
rename Partner partner
rename country exporter
rename partner importer
drop FD_VA*
gen COU="."
replace COU="AUS" if exporter== "Australia"
replace COU="AUT" if exporter=="Austria"
replace COU="BEL" if exporter== "Belgium"
replace COU="CAN" if exporter=="Canada"
replace COU="CZE" if exporter=="Czech Republic"
replace COU="EST" if exporter=="Estonia"
replace COU="FIN" if exporter=="Finland"
replace COU="FRA" if exporter=="France"
replace COU="DEU" if exporter=="Germany"
replace COU="GRC" if exporter=="Greece"
replace COU="HUN" if exporter=="Hungary"
replace COU="IRL" if exporter=="Ireland"
replace COU="ITA" if exporter=="Italy"
replace COU="JPN" if exporter=="Japan"
replace COU="KOR" if exporter=="Korea"
replace COU="LUX" if exporter=="Luxembourg"
replace COU="MEX" if exporter=="Mexico"
replace COU="NLD" if exporter=="Netherlands"
replace COU="POL" if exporter=="Poland"
replace COU="PRT" if exporter=="Portugal"
replace COU="ROU" if exporter=="Romania"
replace COU="RUS" if exporter=="Russian Federation"
replace COU="SVK" if exporter=="Slovak Republic"
replace COU="SVN" if exporter=="Slovenia"
replace COU="ZAF" if exporter=="South Africa"
replace COU="ESP" if exporter=="Spain"
replace COU="TUR" if exporter=="Turkey"
replace COU="GBR" if exporter=="United Kingdom"
replace COU="USA" if exporter=="United States"

gen PAR="."

replace PAR="AUS" if importer== "Australia"
replace PAR="AUT" if importer=="Austria"
replace PAR="BEL" if importer== "Belgium"
replace PAR="CAN" if importer=="Canada"
replace PAR="CZE" if importer=="Czech Republic"
replace PAR="EST" if importer=="Estonia"
replace PAR="FIN" if importer=="Finland"
replace PAR="FRA" if importer=="France"
replace PAR="DEU" if importer=="Germany"
replace PAR="GRC" if importer=="Greece"
replace PAR="HUN" if importer=="Hungary"
replace PAR="IRL" if importer=="Ireland"
replace PAR="ITA" if importer=="Italy"
replace PAR="JPN" if importer=="Japan"
replace PAR="KOR" if importer=="Korea"
replace PAR="LUX" if importer=="Luxembourg"
replace PAR="MEX" if importer=="Mexico"
replace PAR="NLD" if importer=="Netherlands"
replace PAR="POL" if importer=="Poland"
replace PAR="PRT" if importer=="Portugal"
replace PAR="ROU" if importer=="Romania"
replace PAR="RUS" if importer=="Russian Federation"
replace PAR="SVK" if importer=="Slovak Republic"
replace PAR="SVN" if importer=="Slovenia"
replace PAR="ZAF" if importer=="South Africa"
replace PAR="ESP" if importer=="Spain"
replace PAR="TUR" if importer=="Turkey"
replace PAR="GBR" if importer=="United Kingdom"
replace PAR="USA" if importer=="United States"
gen IND="."
replace IND="01-05" if industry=="Agriculture.hunting.forestry.and.fishing"
replace IND="10-14" if industry=="Mining.and.quarrying"
replace IND="15-16" if industry=="Food.products.beverages.and.tobacco"
replace IND="17-19" if industry=="Textiles.textile.products.leather.and.footwear"
replace IND="20" if industry=="Wood.and.products.of.wood.and.cork"
replace IND="21-22" if industry=="Pulp.paper.paper.products.printing.and.publishing"
replace IND="23" if industry=="Coke.refined.petroleum.products.and.nuclear.fuel"
replace IND="24" if industry=="Chemicals.and.chemical.products"
replace IND="25" if industry=="Rubber.and.plastics.products"
replace IND="26" if industry=="Other.non-metallic.mineral.products"
replace IND="27-28" if industry=="Basic.metals.and.fabricated.metal.products"
replace IND="29"	 if industry=="Machinery.and.equipment.nec."
replace IND="30-33" if industry=="Electrical.and.optical.equipment"
replace IND="34-35" if industry=="Transport.equipment"
replace IND="36-37" if industry=="Manufacturing.nec.recycling."
replace IND="40-41" if industry=="Electricity.gas.and.water.supply"
replace IND="45"    if industry=="Construction"
replace IND="50-52" if industry=="Wholesale.and.retail.trade.repairs"
replace IND="55"    if industry=="Hotels.and.restaurants"
replace IND="60-64" if industry=="Transport.storage.post.telecommunication"
replace IND="65-67" if industry=="Financial.intermediation"
replace IND="70-74" if industry=="Real.estate.renting.and.business.activities"
replace IND="75-95" if industry=="Community.social.and.personal.services."
drop if IND=="40-41"

gen EU=0
replace EU=1 if  importer=="Austria"
 replace EU=1 if  importer=="Belgium"
 replace EU=1 if  importer=="Czech Republic"
 replace EU=1 if  importer=="Estonia"
 replace EU=1 if  importer== "Finland"
replace EU=1 if   importer=="France"
replace EU=1 if   importer=="Germany"
replace EU=1 if   importer=="Greece"
replace EU=1 if   importer=="Ireland"
replace EU=1 if   importer=="Italy"
replace EU=1 if importer=="Spain"
replace EU=1 if   importer=="Hungary"
replace EU=1 if   importer=="Slovak Republic"
replace EU=1 if   importer=="Slovenia"
replace EU=1 if   importer=="Portugal"
replace EU=1 if   importer=="Netherlands"
replace EU=1 if   importer=="Luxembourg"
replace EU=1 if   importer=="Poland"
replace EU=1 if   importer=="United Kingdom"

 replace EU=1  if   exporter=="Austria"
   replace EU=1  if exporter=="Belgium"
  replace EU=1  if  exporter=="Czech Republic"
  replace EU=1  if  exporter=="Estonia"
  replace EU=1  if  exporter== "Finland"
 replace EU=1  if   exporter=="France"
 replace EU=1  if   exporter=="Germany"
 replace EU=1  if   exporter=="Greece"
 replace EU=1  if   exporter=="Ireland"
 replace EU=1  if   exporter=="Italy"
 replace EU=1  if   exporter=="Spain"
 replace EU=1  if   exporter=="Poland"
 replace EU=1  if   exporter=="Hungary"
 replace EU=1  if   exporter=="Slovak Republic"
  replace EU=1  if  exporter=="Slovenia"
   replace EU=1  if exporter=="Portugal"
  replace EU=1  if  exporter=="Netherlands"
  replace EU=1  if  exporter=="Luxembourg"
  replace EU=1  if  exporter=="United Kingdom"

gen D_1995=0
replace D_1995=1 if VA_1995!=0

gen D_2000=0
replace D_2000=1 if VA_2000!=0

gen D_2005=0
replace D_2005=1 if VA_2005!=0

gen D_EXGR_1995=0
replace D_EXGR_1995=1 if EXGR_1995!=0

gen D_EXGR_2000=0
replace D_EXGR_2000=1 if EXGR_2000!=0

gen D_EXGR_2005=0
replace D_EXGR_2005=1 if EXGR_2005!=0

bysort D_2000 D_1995: tab D_2005 if D_2000==1 & D_1995==1
bysort IND: tab D_2005 if D_2000==1 & D_1995==1

gen D_im_2000=0
gen D_im=0
gen D_im_exgr=0
 replace D_im_2000=1 if D_2005==0 & D_2000==1
 replace D_im=1 if D_2005==0 & (D_2000==1 | D_1995==1)
 replace D_im_exgr=1 if D_EXGR_2005==0 & (D_EXGR_2000==1 | D_EXGR_1995==1)

replace VA_2005=. if D_im==1
replace EXGR_2005=. if D_im_exgr==1
 replace VA_1995=. if D_1995==0 &VA_2000!=0 & VA_2005!=0
replace EXGR_1995=. if  D_EXGR_1995==0 & D_EXGR_2000!=0 & EXGR_2005!=0

ipolate VA_2005 VA_2000, gen(VA_2005_2) epolate
ipolate VA_1995 VA_2000, gen(VA_1995_2) epolate
replace VA_2005 =VA_2005_2 if VA_2005==.
replace VA_1995  =VA_1995_2 if VA_1995==.
ipolate EXGR_2005 EXGR_2000, gen(EXGR_2005_2) epolate
replace EXGR_2005 =EXGR_2005_2 if EXGR_2005==.
ipolate EXGR_1995 EXGR_2000, gen(EXGR_1995_2) epolate
replace EXGR_1995 =EXGR_1995_2 if EXGR_1995==.

 rename EXGR_2005 EXGR2005
rename EXGR_2000 EXGR2000
rename EXGR_1995 EXGR1995
rename VA_2005 VA2005
rename VA_2000 VA2000
rename VA_1995 VA1995

drop VA_2005_2
drop VA_1995_2
drop EXGR_2005_2
drop EXGR_1995_2

reshape long Producer_price R_D_exp EXGR  VA productivity, i(exporter industry importer) j(year)

drop if year!=2005
eststo clear
*eststo: estpost tab IND
*esttab est* using industry.tex, cells("b ") replace booktabs longtable compress  noobs
*eststo: estpost tab COU
*esttab est2 using cou.tex, cells("b ") replace booktabs longtable compress  label  noobs

egen pair=group(exporter importer)
*construct dest-sector dummies
egen dest_sector=group(industry importer)
gen l_gross_export=ln(EXGR)
gen l_export_va=log(VA)
gen l_productivity=ln(productivity)
gen logrdexpend=ln(R_D_exp)

gen manufac_services=1
replace  manufac_services=0 if IND=="01-05" | IND=="10-14"
gen  no_aggr=1
replace no_aggr=0 if  IND=="17-19" | IND=="50-52" |  IND=="60-64"  |IND=="70-74"|IND=="75-95"
 gen mining=1
replace  mining=0 if IND=="10-14"

gen manufac=1
replace manufac=0 if IND=="01-05" | IND=="10-14"  | IND=="45" | IND=="50-52" | IND=="55" | IND=="60-64" | IND=="65-67"|  IND=="70-74" |  IND=="75-95"
eststo clear
set more off
	sort exporter industry importer
		*exporter dummies
	quietly:tabulate exporter, generate(idum)
*importer dummies
	quietly:tabulate importer, generate(jdum)

	foreach var1 of varlist idum* {
		foreach var2 of varlist jdum* {
 generate alpha`var1'`var2'=`var1'*`var2'
			}
		}

	quietly: tabulate industry, generate(kdum)
	foreach var1 of varlist idum* {
		foreach var2 of varlist kdum* {
		 generate gamma`var1'`var2'=`var1'*`var2'
			}
		}

	foreach var1 of varlist kdum* {
		foreach var2 of varlist jdum* {
		generate beta`var1'`var2'=`var1'*`var2'
		}
	}

	/*  Collinearity
areg  l_productivity logrdexpend I.dest_sector , absorb(pair)
vif , uncentered
predict productivity_hat_2, xb
areg l_gross_export productivity_hat_2 I.dest_sector, absorb(pair)  vce(robust)
vif , uncentered
both stages collinearity problem first stage more severe than second stage
*/

#OLS IV with two dimensions of fixed effects
eststo clear
eststo: reghdfe  l_gross_export l_productivity , vce(robust) absorb(pair dest_sector)
    eststo: reghdfe l_gross_export (l_productivity=logrdexpend)   , absorb(pair dest_sector) vce(robust)  ffirst
  eststo: reghdfe l_gross_export  (l_productivity=logrdexpend )    if  manufac_services==1, absorb(pair dest_sector) vce(robust) ffirst
   eststo: reghdfe l_gross_export  (l_productivity=logrdexpend )    if  mining==1, vce(robust) ffirst absorb(pair dest_sector)
    eststo: reghdfe l_gross_export (l_productivity=logrdexpend )    if  EU==1, vce(robust) ffirst absorb(pair dest_sector)
*esttab est1  est2 est3 est4 est5  using ricardo_gr_exp_second.tex , replace scalar(F r2u widstat) r2 se keep ( l_productivity ) b(2) 	 booktabs  mtitles("OLS" "Full Sample"  "Manufacturing Service" "Without mining" "EU")
esttab est1  est2 est3 est4 est5 using ricardo_gr_exp_second.html , replace scalar(F r2u widstat) r2 se keep ( l_productivity ) b(2) 	   mtitles("OLS"  "Full Sample"  "Manufacturing Service" "Without mining" "EU")
eststo:reghdfe l_export_va  l_productivity   , vce(robust) absorb(pair dest_sector)
 eststo: reghdfe l_export_va  (l_productivity=logrdexpend  )   , vce(robust) ffirst absorb(pair dest_sector)
  eststo: reghdfe l_export_va  (l_productivity=logrdexpend )    if  manufac_services==1, vce(robust) ffirst absorb(pair dest_sector)
   eststo: reghdfe l_export_va  (l_productivity=logrdexpend )    if  mining==1, vce(robust) ffirst absorb(pair dest_sector)
    eststo: reghdfe l_export_va (l_productivity=logrdexpend )    if  EU==1, vce(robust) ffirst absorb(pair dest_sector)

*esttab est6  est7 est8 est9 est10  using ricardo_va_exp_new.tex, replace scalar(F r2u widstat) r2 se keep ( l_productivity ) b(2) 	 booktabs    mtitles("OLS"  "Full Sample"  "Manufacturing Service" "Without mining" "EU")
esttab est6  est7 est8 est9 est10    using  ricardo_va_exp_new.html, replace scalar(F r2u widstat) r2 se keep ( l_productivity ) b(2)     mtitles("OLS"  "Full Sample"  "Manufacturing Service" "Without mining" "EU")
save thesis_data2_FD_VA_va_exgr_rd_price_03_sep_2015.dta

log close

error: pathspec 'trade_elasticity.do' did not match any file(s) known to git


added default .txt.do

added default .txt.do

error: pathspec 'default.txt.do' did not match any file(s) known to git


initalize the step5

initalize the step5

/* change this */
cd ~/GitHub/inventory_dynamics/empirics/agg_empirics/codes

/* Housekeeping */
clear all
set matsize 5000
set more off

/* save rawly processed dataset */
use ../data/quarterly_FRED, clear

/* gen some variables */
gen ln_rSalesGoods = log(rSalesGoods)

/* firstly let's check for the cointegration */
vec ln_rInventory ln_rSalesGoods, trend(constant) lags(4)
vecrank ln_rInventory ln_rSalesGoods, trend(constant) lags(4)

error: pathspec 'empirics/agg_empirics/codes/STEP5_simple_coint_markov.do' did not match any file(s) known to git


ENH: Add mat2nparray for dumpy Stata matrices to np arrays

capture program drop mat2array
program define mat2array
    version 11.2
    syntax namelist(min=1), SAVing(str) [ Format(str) APPend REPlace ]
    if "`format'"=="" local format "%16.0g"
    local saving: subinstr local saving "." ".", count(local ext)
    if !`ext' local saving "`saving'.py"
    tempname myfile
    file open `myfile' using "`saving'", write text `append' `replace'
    file write `myfile' "import numpy as np" _n _n

    foreach mat of local namelist {
        mkarray `mat' `myfile' `format'
    }
file close `myfile'
end

capture program drop mkarray
program define mkarray

    args mat myfile fmt
    local nrows = rowsof(`mat')
    local ncols = colsof(`mat')
    local i 1
    local j 1
    file write `myfile' "`mat' = np.array(["
    local justifyn = length("`mat' = np.array([")
    forvalues i=1/`nrows' {
        forvalues j = 1/`ncols' {
            if `i' > 1 | `j' > 1 { // then we need to indent
                forvalues k=1/`justifyn' {
                    file write `myfile' " "
                }
            }
            if `i' < `nrows' | `j' < `ncols' {
                file write `myfile' `fmt' (`mat'[`i',`j']) ", " _n
            }
            else {
                file write `myfile' `fmt' (`mat'[`i',`j'])
            }
        }
    }

    if `nrows' == 1 | `ncols' == 1 {
        file write `myfile' "])" _n _n
    }
    else {
        file write `myfile' "]).reshape(`nrows',`ncols')" _n _n
    }
end

error: pathspec 'tools/mat2nparray.ado' did not match any file(s) known to git


killer pic code

killer pic code

program killer_pic2

use ${stash}master, clear

local decay 0.999
local mode `1'

keep if isbaseball == `mode'
keep id isbaseball debut year img finalyear

reshape wide img, i(id) j(year)

gen diff = img2013 - img2008
gen percent = (1964 - debut) / (finaly - debut)
replace percent = 1 if percent <= 0
replace percent = 1 if percent >= 1

gen before = (debut < 1964)

gen cutoff = 1963.5

by debutyear, sort: egen meanpct = mean(percent)
by debutyear, sort: egen meangrp = mean(diff)
by debutyear, sort: drop if _n > 1

gen meandiff = meangrp / meanpct

replace meanpct = 0.001 if debutyear>=1964
replace meanpct = meanpct * -1
replace meanpct = meanpct - 0.5

tw (bar meandiff debutyear if debutyear < 1964, barwidth(0.75) color(gs2)) (bar meandiff debutyear if debutyear >= 1964, barwidth(0.75) color(gs8)),  title("") xtitle("Player Debut Appearance Year") ytitle("Images Added Between 2008-2013 (Rescaled)") xsca(titlegap(3) range(1944 1984) noextend) ysca(axis(1) titlegap(2) range(-0.2 2.5)) xline(1963.5, noextend lcolor(gs4)) xlabel(1944(4)1984) ylabel(0(0.5)5,nogrid) legend(off)

//text(-0.5 1948 "Percent In-Copyright", place(e)) legend(off)

/*tw (bar meandiff debutyear if debutyear < 1964, barwidth(0.75) color(gs2)) (bar meandiff debutyear if debutyear >= 1964, barwidth(0.75) color(gs8)) (line meanpct debutyear, color(gs1)),  title("Change in Images for Baseball Players (Rescaled)") xtitle("Player Debut Appearance Year") ytitle("Images Added After Digitization (Rescaled)") xsca(titlegap(3) range(1944 1984) noextend) ysca(axis(1) titlegap(2) range(-0.2 2.5)) ysca(axis(1) titlegap(2) range(-1 0.1)) xline(1963.5, noextend lcolor(gs4)) xlabel(1944(4)1984) ylabel(0(0.5)5,nogrid)  text(-0.5 1948 "Percent In-Copyright", place(e)) legend(off)

legend(label(1 "`nocopyright' (Before 1964)") label(2 "`incopyright' (After 1964)")) legend(order(1 2))*/

graph export "${tables}killerpic2_`mode'.eps", replace
shell epstopdf "${tables}killerpic2_`mode'.eps"

end

error: pathspec 'scripts/stata/ado/killer_pic2.ado' did not match any file(s) known to git


Create multiple imputation reg.do

Create multiple imputation reg.do

Multiple imputation and complete data analysis of EXGR | Value Added exports and the inverse of producer prices (=productivity) instrumented by R & D expenditures

error: pathspec 'multiple' did not match any file(s) known to git
error: pathspec 'imputation' did not match any file(s) known to git
error: pathspec 'reg.do' did not match any file(s) known to git


add example for estmat2nparray

add example for estmat2nparray

/* Run Survival models and save results

Author: Josef Perktold
based on example from Stata help

*/

clear
*basic Kaplan-Meier
capture use "E:\Josef\statawork\stan3.dta", clear
if _rc != 0 webuse stan3
capture save "E:\Josef\statawork\stan3.dta"
capture erase surf.dta
sts list,  saving("surf")
use "E:\Josef\statawork\surf.dta", clear
outsheet using "surv_km.csv", comma replace

* Kaplan-Meier with by
use "E:\Josef\statawork\stan3.dta", clear
capture erase surf2.dta
sts list, by(posttran)  saving("surf2")
use "E:\Josef\statawork\surf2.dta", clear
outsheet using "surv_km2.csv", comma replace

* Cox Proportional Hazard
use "E:\Josef\statawork\stan3.dta", clear
stcox age posttran ,  estimate norobust
ereturn list,
matlist e(V)
matlist e(p)

* the next doesn't work
* predict predictall, hr xb stdp basesurv basechazard basehc mgale csnell deviance ldisplace lmax effects
/* generate in python:
>>> for i in 'hr xb stdp basesurv basechazard basehc mgale csnell deviance ldisplace lmax effects'.split(): print 'predict %s, %s' % (i,i)
*/
predict hr, hr
predict xb, xb
predict stdp, stdp
predict basesurv, basesurv
predict basechazard, basechazard
predict basehc, basehc
predict mgale, mgale
predict csnell, csnell
predict deviance, deviance
predict ldisplace, ldisplace
predict lmax, lmax
*capture predict effects, effects

outsheet hr xb stdp basesurv basechazard basehc mgale csnell deviance ldisplace lmax using "surv_coxph.csv", comma replace

* replay
stcox

matrix cov = e(V)
svmat cov, names(cov)

* get the colnames and rownames
capture drop nacol narow
matrix params_table = r(table)'
gen nacol = "`: colnames params_table'"
gen narow = "`: rownames params_table'"
di nacol
di narow

*2nd version

capture drop rown2
local colnms: coln params_table
gen str rown2 = "`colnms'"
di rown2

svmat params_table, names(params_table)
estmat2nparray params_table cov, saving("results_coxphrobust.py") format("%16.0g") append
* other options, no matrices or no est results
*estmat2nparray params_table cov, saving("results_coxphrobust_2.py") format("%16.0g") append noest
*estmat2nparray , saving("results_coxphrobust_2.py") format("%16.0g") append

error: pathspec 'tools/km_cox1.do' did not match any file(s) known to git


Add default.types-distr.json.do

Add default.types-distr.json.do

#!/usr/bin/env python3
from collections import defaultdict, OrderedDict
import json, yaml
import redo
from pathlib import Path
from data import Databases, Mappings, Concepts

def is_concept_relevant(codes_by_coding_systems, mapping, databases):
    for database in databases.databases():
        coding_system = databases.coding_system(database)
        reference = mapping.codes(database)
        generated = codes_by_coding_systems.codes(coding_system)
        if reference is not None:
            generated = codes_by_coding_systems.codes(coding_system)
            if set(reference) & set(generated):
                return True
    return False

def get_pos_neg_codes(codes_by_coding_systems, mapping, databases):
    pos, neg = [], []
    for database in databases.databases():
        coding_system = databases.coding_system(database)
        reference = mapping.codes(database)
        generated = codes_by_coding_systems.codes(coding_system)
        if reference is not None:
            pos += generated & reference
            neg += generated - reference
    return pos, neg

def get_types_distr(concepts, mapping, semantic_types, databases):
    types_distr = defaultdict(lambda: OrderedDict([
        ('pos-concepts', []),
        ('neg-concepts', []),
        ('pos-codes', []),
        ('neg-codes', []),
    ]))
    for cui in concepts.cuis():
        codes_by_coding_systems = concepts.codes_by_coding_systems(cui)
        relevant = is_concept_relevant(codes_by_coding_systems, mapping, databases)
        pos_codes, neg_codes = get_pos_neg_codes(codes_by_coding_systems, mapping, databases)
        for st in concepts.types(cui):
            types_distr[st]['pos-concepts' if relevant else 'neg-concepts'].append(cui)
            types_distr[st]['pos-codes'] += pos_codes
            types_distr[st]['neg-codes'] += neg_codes
    return dict(types_distr)

if redo.running():

    project, event = redo.snippets
    project_path = Path('projects') / project

    with redo.ifchange(project_path / 'config.yaml') as f:
        config = yaml.load(f)
        databases = Databases.of_config(config)
        semantic_types = config['semantic-types']

    with redo.ifchange(project_path / 'events.yaml') as f:
        events = yaml.load(f)

    with redo.ifchange(project_path / 'mappings.yaml') as f:
        mappings = Mappings.of_raw_data_and_normalize(yaml.load(f), events, databases)
        mapping = mappings.get(event)

    with redo.ifchange('{}.{}.concepts.json'.format(project, event)) as f:
        concepts = Concepts.of_data(json.load(f))

    types_distr = get_types_distr(concepts, mapping, semantic_types, databases)

    with redo.output() as f:
        json.dump(types_distr, f)

error: pathspec 'evaluation/do/default.types-distr.json.do' did not match any file(s) known to git


iegraph : initial and recognice betas

iegraph : initial and recognice betas

initial set up. Command now recognize betas

cap	program drop	ieimpgraph
	program define 	ieimpgraph

	syntax varlist

	mat list e(b)

	foreach var of local varlist {

		local beta = _b[`var']

		di "`beta'"

	}

end

cap	program drop	tobeused
	program define 	tobeused

	capture file close `textfile'_`date'
	file open  `textfile'_`date' using `textfile'_`date'.txt, text write replace
	file write `textfile'_`date' ///
		"Variable" 	_tab "Tmt-Status"	_tab "mean" _tab "coeff" _tab "conf_int_min" _tab "conf_int_max" _tab "obs" _tab "star" _n
	file close `textfile'_`date'

	local REG_RESULTS ""
	foreach depvar of local depvars {

		rename lag2_`depvar' lagvar

		local regname `depvar'
			eststo `regname' : areg `depvar' tmt_reg tmt_sdp tmt_inc lagvar NoCropBoroBL NoCropBL incorrect_no_bl NoPlotDataBL NoHarvValueDataBL if t == 2, a(d_code) cl(v_code)
		local  REG_RESULTS "`REG_RESULTS' `regname'"

		foreach tmt_arm in reg sdp inc {
			scalar coeff_`tmt_arm' 		= _b[tmt_`tmt_arm']
			scalar coeff_se_`tmt_arm' 	= _se[tmt_`tmt_arm']

			sum `depvar' if e(sample) & tmt_`tmt_arm' == 1
			scalar obs_`tmt_arm'	= r(N)
		}

		sum `depvar' if e(sample) & tmt_reg == 0 & tmt_sdp == 0 & tmt_inc == 0
		scalar ctl_N		= r(N)
		scalar ctl_mean	  	= r(mean)
		scalar ctl_mean_sd 	= r(sd)

		estadd scalar ctl_mean_table	=r(mean)
		estadd scalar ctl_N_table		=r(N)
		estadd scalar ctl_mean_sd_table	=r(sd)

		sum lagvar if e(sample) & !(NoCropBoroBL == 1 | NoCropBL == 1 | incorrect_no_bl == 1 | NoPlotDataBL == 1 | NoHarvValueDataBL == 1)
		scalar BL_mean 		= r(mean)
		scalar BL_N 	= r(N)

		estadd scalar BL_mean_table	=r(mean)
		estadd scalar BL_N_table	=r(N)

		rename lagvar lag2_`depvar'

		foreach tmt_arm in reg sdp inc {
			scalar  conf_int_min_`tmt_arm'   =coeff_`tmt_arm'-(1.96*coeff_se_`tmt_arm') + ctl_mean
			scalar  conf_int_max_`tmt_arm'   =coeff_`tmt_arm'+(1.96*coeff_se_`tmt_arm') + ctl_mean

			test    tmt_`tmt_arm'

			scalar  pvalue =r(p)
			local star_`tmt_arm'
			if pvalue < 0.10 {
				local star_`tmt_arm' "*"
			}
			if pvalue < 0.05 {
				local star_`tmt_arm' "**"
			}
			if pvalue < 0.01 {
				local star_`tmt_arm' "***"
			}

			scalar tmt_mean_`tmt_arm' = ctl_mean + coeff_`tmt_arm'
		}

		file open  `textfile'_`date' using `textfile'_`date'.txt, text write append
		file write `textfile'_`date' ///
			"`regname'" _tab "Control"  _tab %9.3f (ctl_mean)      _tab  		 			_tab 		 			  	  _tab 			 				_tab %9.3f (ctl_N) 	   _tab			  	  _n ///
			"`regname'" _tab "reg"		_tab %9.3f (tmt_mean_reg)  _tab  %9.3f (coeff_reg)  _tab %9.3f (conf_int_min_reg) _tab %9.3f (conf_int_max_reg) _tab %9.3f (obs_reg)   _tab "`star_reg'"  _n ///
			"`regname'" _tab "sdp"		_tab %9.3f (tmt_mean_sdp)  _tab  %9.3f (coeff_sdp)  _tab %9.3f (conf_int_min_sdp) _tab %9.3f (conf_int_max_sdp) _tab %9.3f (obs_sdp)   _tab "`star_sdp'"  _n ///
			"`regname'" _tab "inc"		_tab %9.3f (tmt_mean_inc)  _tab  %9.3f (coeff_inc)  _tab %9.3f (conf_int_min_inc) _tab %9.3f (conf_int_max_inc) _tab %9.3f (obs_inc)   _tab "`star_inc'"  _n
		file close `textfile'_`date'

	}
	esttab `REG_RESULTS' using "$csv/outcomeVar_AllTreat_`date'.csv",      ///
		title(`tabeleFileName') stats(BL_mean_table BL_N_table ctl_mean_table ctl_N_table ctl_mean_sd_table N) mtitles nonumbers plain br  star(* 0.10 ** 0.05 *** 0.01) ///
		b(a3)  se(%9.2f) alignment(l) replace

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

		Produce the graphs

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

	insheet using `textfile'_`date'.txt, clear tab

	pause on

	cd "$graphs/gRaw"

	gen tmt = .
	replace tmt = 1 if tmtstatus == "Control"
	replace tmt = 2 if tmtstatus == "reg"
	replace tmt = 3 if tmtstatus == "sdp"
	replace tmt = 4 if tmtstatus == "inc"

	gen placement = tmt

	*gen 	placement = tmt if demo_code == 1
	*replace placement = tmt + 5 if demo_code == 2

	foreach percentVar in mean coeff conf_int_min conf_int_max {

		replace `percentVar' =  `percentVar' * 100 if variable == "c1_commerce"
	}

	gen 	labelString 		= ""
	gen 	labelCategory		= .
	local 	continVars_Large  	c1_harv_value c1_net_yield c1_gross_yield c1_total_earnings c2_inp_total_spending c1_IAAP_harv_value c1_net_yield_nonLabor c1_net_yield_allLabor
	local 	continVars_Small  	c1_total_plotsize
	local 	percentage_Vars   	c1_commerce

	foreach L_var of local continVars_Large {

		replace labelCategory = 1 if variable == "`L_var'"
	}
	foreach S_var of local continVars_Small {

		replace labelCategory = 2 if variable == "`S_var'"
	}
	foreach P_var of local percentage_Vars {

		replace labelCategory = 3 if variable == "`P_var'"
	}

	tempvar labelString_temp decimal_postion

	tostring mean,	gen(`labelString_temp') force
	gen 	`decimal_postion' = strpos(`labelString_temp',".")

	*For continious values without decimal point (means include all in practice)
	replace `decimal_postion' = 10 if  `decimal_postion' == 0

	replace labelString = substr(`labelString_temp',1,(`decimal_postion'-1)) 		if labelCategory == 1
	replace labelString = substr(`labelString_temp',1,4) 							if labelCategory == 2
	replace labelString = substr(`labelString_temp',1,`decimal_postion'+1) + "%"	if labelCategory == 3

	tempfile restart_loop
	save 	`restart_loop', replace

	levelsof variable
	foreach level in `r(levels)' {
		use `restart_loop', clear
		di "`level'"
		keep if variable == "`level'"

		foreach tmt in reg sdp inc {
			preserve
				keep if tmtstatus == "`tmt'"
				local obs_`tmt'  = obs[1]
				local star_`tmt' = star[1]
			restore
		}

		preserve
			keep if tmtstatus == "Control"
			local obs_ctrl  = obs[1]
		restore

		local title "ERROR"

		if "`level'" == "c1_IAAP_harv_value"	local title "Harvest value IAPP crops, Taka"
		if "`level'" == "c1_commerce"			local title "Commercialization, earnings/production %"
		if "`level'" == "c1_gross_yield"		local title "Gross yield, Taka/Ha"
		if "`level'" == "c1_gross_yield_comp"	local title "Gross yield, plots with completed harvest, Taka/Ha"
		if "`level'" == "c1_gross_yield_harv" 	local title "Gross yield, actaully harvested all plots, Taka/Ha"
		if "`level'" == "c1_harv_value"			local title "Total value all harvest, Taka"
		if "`level'" == "c1_harv_value_int"		local title "Total value harvest intercropped, Taka"
		if "`level'" == "c1_harv_value_mono" 	local title "Total value harvest monocropped, Taka"
		if "`level'" == "c1_net_yield"			local title "Net yield, Taka/Ha"
		if "`level'" == "c1_total_earnings"		local title "Total earnings all crop sales, Taka"
		if "`level'" == "c1_total_plotsize"		local title "Total plotsize, Ha"
		if "`level'" == "c2_inp_total_spending"	local title "Total input spending, Taka"

		local noyscale ylabel(#3) ytitle("")
		*if "`title'" != "Boro" & "`title'" != "Lentil" & "`title'" != "Mustard" local noyscale ysc(off)

		if "`level'" == "c2_inp_total_spending"	local noyscale ylabel(#2) ytitle("")
		if "`level'" == "c1_gross_yield"		local noyscale ylabel(#2) ytitle("")

		local graphname	gph_`textfile'_`level'
		sort placement
		graph twoway (bar mean placement if tmt == 1, color("17 33 44")	 ) ///
			(bar mean placement if tmt == 2 , color("228 202 194") 		) ///
			(bar mean placement if tmt == 3 , color("215 107 96" ) 		 ) ///
			(bar mean placement if tmt == 4 , color("156 36  24" ) 		) ///
			(rcap conf_int_max conf_int_min placement, lc(gs) 						) ///
			(scatter  mean placement, msym(none) mlab(labelString) mlabs(medium) mlabpos(10) mlabcolor(black))	, ///
			legend(order(1 2 3 4) lab(1 "Control") lab(2 "Regular Treatment") lab(3 "Shared Demo Treatment") lab(4 "Incentives Treatment")) ///
			 plotregion(margin(b+3 t+3)) ///
			xlabel(	1 `" (N = `obs_ctrl') "' ///
					2 `" "(N = `obs_reg')" " `star_reg' " "' ///
					3 `" "(N = `obs_sdp')" " `star_sdp' " "' ///
					4 `" "(N = `obs_inc')" " `star_inc' " "', noticks labsize(medsmall)) ///
			graphregion( lcolor("182 222 255") fcolor("182 222 255")) ///
			plotregion(fcolor("247 247 247") ) ///
		   	xtitle("") ``level'_lab' `noyscale'  ///
			title("`title'") saving(`graphname'.gph, replace)
			graph export `graphname'.png, replace
		*pause
	}

	*Main outcomes
	cd "$graphs/gRaw"
	grc1leg gph_ag_outcome_log_c1_harv_value.gph 	///
			gph_ag_outcome_log_c1_net_yield.gph 	///
			gph_ag_outcome_log_c1_gross_yield.gph 	///
			gph_ag_outcome_log_c1_total_earnings.gph 	///
		,saving(gph_ag_outcome_log_MAIN.png, replace) /*ycom*/ ///
		cols(2) imargin(small) graphregion( lcolor("182 222 255") fcolor("182 222 255"))
	graph use gph_ag_outcome_log_MAIN.png
	graph display, xsize(8.5)

	cd "$graphs/"
	graph export gph_ag_outcome_log_MAIN.eps, preview(on) replace

	pause

	*Other ag outcomes
	cd "$graphs/gRaw"
	grc1leg gph_ag_outcome_log_c2_inp_total_spending.gph 	///
			gph_ag_outcome_log_c1_total_plotsize.gph 	///
			gph_ag_outcome_log_c1_IAAP_harv_value.gph 	///
			gph_ag_outcome_log_c1_commerce.gph 	///
		,saving(gph_ag_outcome_log_other.png, replace) /*ycom*/ ///
		cols(2) imargin(small) graphregion( lcolor("182 222 255") fcolor("182 222 255"))
	graph use gph_ag_outcome_log_other.png
	graph display, xsize(8.5)

		cd "$graphs/"
	graph export gph_ag_outcome_log_other.eps, preview(on) replace

	cap log close `logname'
end

error: pathspec 'ieimpgraph.do' did not match any file(s) known to git


iefolder : test create main master dofile

	ieboilstart, v(11.1)
	`r(version)'

	global box 		"C:\Users\wb462869\Box Sync"
	global ief 		"$box\Stata\Stata work\Commands\iefolder"
	global testdir	"$ief\ief_test"

	do "$ief\functions.do"

	cd "$ief\cdjunk"

	local maindirname datawork

	local maindir "$testdir/`maindirname'"

	local oldfilename "`maindir'/testMasterDofile.do"

	tempfile	newtextfile
	tempname oldfile newfile

	file open  		`newfile' using "`newtextfile'", text write replace
	file close 		`newfile'

	masterDofilePart0 `newtextfile' `newfile'
	masterDofilePart1 `newtextfile' `newfile'	"`maindir'"

	copy "`newtextfile'"  "$maindir/testMasterDofileGen3.do" , replace

	doedit "$maindir\testMasterDofileGen3.do"

error: pathspec 'masterdofile_create.do' did not match any file(s) known to git


add run util prog for recursive delete folder

* This file can delete all your folders on your computer if used incorrectly.

cap program drop ie_recurse_rmdir
	program define ie_recurse_rmdir

qui {
	syntax , folder(string) [DRYrun okifnotexist]

	/*
		folder - full path to folder which should be deleted with all its content
		dryrun - just list and do not delete all files that would have been deleted without this option
		okifnotexist - it is ok that the top folder does not exist, do not throw erroe

	*/

	*Test that folder exist
	mata : st_numscalar("r(dirExist)", direxists("`folder'"))

	if (`r(dirExist)' == 0) {
		if missing("`okifnotexist'") {
			noi di as error `"{phang}The folder used in [folder(`folder')] does not exist.{p_end}"'
			error 693
			exit
		}
		else {
			*Folder is missin and that is ok, just output a confirmation that it does not exists
			noi di as result `"{phang}The folder used in [folder(`folder')] is already deleted.{p_end}"'
		}
	}
	else {

		 if (length("`folder'")<=10) {
			noi di as error `"{phang}The folder used in [folder(`folder')] does not exist or you have not entered the full path.{p_end}"'
			error 693
			exit
		}

		* File paths can have both forward and/or back slash. We'll standardize them so they're easier to handle
		local folderStd			= subinstr(`"`folder'"',"\","/",.)

		*List files, directories and other files
		local flist : dir `"`folderStd'"' files "*"	, respectcase
		local dlist : dir `"`folderStd'"' dirs  "*" , respectcase
		local olist : dir `"`folderStd'"' other "*"	, respectcase

		*Use the command on each subfolder to this folder (if any)
		foreach dir of local dlist {
			*Recursive call on each subfolder
			noi ie_recurse_rmdir , folder(`"`folderStd'/`dir'"') `automatic' `dryrun'
		}

		*REmove all files
		local files `"`flist' `olist'"'
		foreach file of local files {
			*If dryrun then list otherwise delete
			if !missing("`dryrun'") noi di as result "{pstd}DRY RUN! Without option {bf:dryrun} file [`folderStd'/`file'] would have been deleted.{p_end}"
			else rm `"`folderStd'/`file'"'
		}

		* Remove this folder as it is now empty
		if missing("`dryrun'") {
			rmdir `"`folderStd'"'
			noi di as result "{pstd}Fodler [`folderStd'] and all its content was deleted.{p_end}"
		}
	}
}
end

error: pathspec 'run/ie_recurse_rmdir.do' did not match any file(s) known to git


aborted separate regressions

aborted separate regressions

program reg_layers

make_data
run_reg
write_reg

end

program make_data

use ${stash}paneluid, clear

bysort unitid: egen numtime = total(numcontrib>0)
bysort unitid: egen numtime_contrib = total(numcontrib)

replace treat = (treat>0.20)

gen firstq =  qofd(dofm(firstm))

bysort unitid: gen tag=_n==1
format firstm %tm

gen regular = (firstq < 191)

end

program run_reg

local depvars "numcontrib numcontrib_notreat numcontrib_statenotreat numcounties"

local depvars "numcontrib numcontrib_notreat numcontrib_statenotreat numcounties"
local depvars "numcontrib"

foreach x in `depvars'{
    est clear

    gen ln`x' = ln(`x'+1)

    eststo est1: qui xtreg ln`x' treat##post i.year, fe cluster(uid)
    qui estadd local yearfe "Yes"
    qui estadd local countyfe "Yes"
    estimates save ${myestimates}reg_person_`x'_1, replace

    eststo est2: qui xtpoisson `x' treat##post i.year, fe vce(robust)
    qui estadd local yearfe "Yes"
    qui estadd local countyfe "Yes"
    estimates save ${myestimates}reg_person_`x'_2, replace

}

end

program load_reg
local x `1'
est clear
forval y = 1(1)2{
    estimates use ${myestimates}reg_person_`x'_`y'
    eststo est`x'_`y'
  }
end

program write_reg

localdef

load_reg numcontrib
load_reg numcontrib_notreat

esttab, keep(1.treat#1.post) p

esttab using "${tables}reg_layers.tex", ${top} posthead("\midrule \textbf{Panel A : Other Layers}\\")

load_reg numattrib12
esttab using "${tables}reg_layers.tex",  ${middle} posthead("\midrule \textbf{Panel B : Class1 Attrib}\\")

load_reg numattrib3
esttab using "${tables}reg_layers.tex",   ${end} posthead("\midrule \textbf{Panel C : Class3 Attrib}\\")

/*load_reg numattrib4
esttab using "${tables}reg_layers.tex",  ${end} posthead("\midrule \textbf{Panel D : Class4 Roads}\\")
*/

end

program localdef

global top "drop(*.year 0b* 1o* 1.post _cons) star(+ 0.15 * 0.10 ** 0.05 *** 0.01) se ar2 nonotes coeflabels(1.treat#1.post "TIGER X POST") booktabs order(1.treat#1.post)  stats(, labels()) nomtitles nocons replace width(\hsize) postfoot(\end{tabular*} }) prefoot("") varwidth(25) eqlabels("") noisily"

global middle "drop(*.year 0b* 1o* 1.post _cons) star(+ 0.15 * 0.10 ** 0.05 *** 0.01) se ar2 nonotes coeflabels(1.treat#1.post "TIGER X POST") booktabs order(1.treat#1.post)  stats(, labels()) nomtitles nocons width(\hsize) postfoot(\end{tabular*} }) prefoot("") append collabels(none) prehead(`"{"' `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' \begin{tabular*}{\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l*{@E}{c}}) nonumbers eqlabels("")"

global end "drop(*.year 0b* 1o* _cons 1.post) star(+ 0.15 * 0.10 ** 0.05 *** 0.01) se ar2 nonotes coeflabels(1.treat#1.post "TIGER X POST") booktabs order(1.treat#1.post) s(countyfe yearfe N N_g, label("County FE" "Year FE" N "Clusters")) nomtitles nocons append width(\hsize) nonumbers prehead(`"{"' `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' \begin{tabular*}{\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l*{@E}{c}}) eqlabels("")"
/* \""'' */
/* \""' */
** ""

end

error: pathspec 'stata/ado/reg_person.ado' did not match any file(s) known to git


Create winsorize.ado

Create winsorize.ado

cap pr drop winsorize
pr def winsorize, rclass
	version 6
	syntax varlist [, GENerate(name) AT(numlist max = 2) LIMits(numlist)]
	loc ncutpoints : list sizeof at
	if `ncutpoints' > 2 {
		di "Cannot have more than 2 cutpoints"
		error
	}
	else if `ncutpoints' > 0 {
		if `ncutpoints' != 1 {
			tokenize `at'
			loc upper `1'
			loc lower `2'
		}
		else {
			loc lower 0
			loc upper `at'
		}
	}
	else {
		loc lower 0
		loc upper 99
	}
	if "`limits'" == "" {
		loc lower `limits'
		loc upper `=1-`limits''
	}
	if "`generate'" != "" {
		loc targetvar `generate'
		g `targetvar' = `varlist'
	}
	else {
		loc targetvar `varlist'
	}
	if `lower' != 0 {
		_pctile `varlist' , p(`lower' `upper')
		loc ll = r(r1)
		loc ul = r(r2)
		replace `targetvar' = `ll' if `varlist' == `ll'
	}
	else {
		_pctile `varlist' , p(`upper')
		loc ul = r(r1)
		loc ll "."
	}
	replace `targetvar' = `ul' if `varlist' > `ul'
	return scalar lower = `ll'
	return scalar upper = `ul'
	return local targetvar `targetvar'
end

error: pathspec 'winsorize.ado' did not match any file(s) known to git


STATA code to tabulate only top occurences and plot them

sysuse auto

// Tabulate all mpgs
tab mpg, descending

// Only top 5 frequencies
ssc install groups
groups mpg, order(h) select(5)

// Now lets plot only those top 5
// matcell and matrow save the results
tabulate mpg, sort matcell(freq) matrow(mpg)
// svmat turns those results into variables
svmat freq
svmat mpg
// drop the 6th through last (-1) entries if there are any
// since we only want the top 5
replace freq1 = . in 6/-1
replace mpg1 = . in 6/-1
graph bar freq1, over(mpg1)

error: pathspec 'plotting/plot-top-frequencies/plot-top-freqs.do' did not match any file(s) known to git


(interim) syntax replacement

(interim) syntax replacement

cap pr drop _fvunab
pr _fvunab, sclass
	* Variant of -fvunab- that does not expand x##y
	loc remainder `0'

	while ("`remainder'" != "") {
		gettoken 0 remainder: remainder, parse(" #.()=")
		loc next_char = substr("`remainder'", 1, 1)
		if !inlist("`0'", "#", ".", "(", ")", "=") & ("`next_char'" != ".") {
			syntax varlist(numeric fv ts)
			loc 0 `varlist'
		}
		if ("`next_char'" != " ") loc next_char
		loc answer "`answer'`0'`next_char'"
	}
	sreturn local varlist `answer'
end

/* USAGE:
sysuse auto
_fvunab F2.pri   tu##c.L.trun#ibn.foreign (pri	= tu##for#c.pri) weigh
di "`s(varlist)'"
*/

error: pathspec 'source/common/_fvunab.ado' did not match any file(s) known to git