generic cross-validation routine

generic cross-validation routine

this should not be a part of the svm package, but it might end up getting released with it

/* cv: cross-validated predictions from any Stata estimation command.
 *
 * Breaks a dataset into a number of subsets ("folds"), and for each
 * runs an estimator on everything but that subset, and predicts results.
 * In this way, the fit is unbiased by the estimation process, because
 * each prediction is made from data which were never involved in fitting.
 * Sometimes this is described as a way to control overfitting.
 *
 *
 * In general there are two ways to measure the performance of an estimator:
 *  looking at its residuals -- in machine learning jargon, the training error
 *  looking at its cross-validated residuals -- the cross-validation error
 * The cv error is an estimate of the generalization error --- the performance
 * of your model on data it has never seen before --- which is usually what you care about in applications.
 * The ratio of the two tells you if you are over- or under- fitting:
 *  - if training error is higher, you are underfitting---you do not have enough degrees of freedom in your model---because the training is not doing as well on the full dataset as it does on slices (this is rare)
 *  - if training error is lower, you are overfitting---you have too many degrees of freedom, and you're fitting noise instead of signal---, because the training error is underestimating the generalization error.
 *
 * (There is also a third measurement:
 *  looking at it's test-set residuals -- the testing error
 * Cross-validation is usually used in conjunction with grid-search to tune tuning-parameters.
 * This in itself can be thought of as a type of estimation, and hence keeping a spare set of data
 * purely for testing immunizes your performance from overfitting in the grid-search,
 * even though each individual section of grid-search should be immune from overfitting.)
 *
 *
 * syntax:
 * cv estimator target y x1 x2 x3 ... [if] [in], folds(#) [shuffle] [options to estimator]
 *
 * estimator should be a standard Stata estimation command which can be followed by a call to "predict target if"
 * pass folds(_N) (and no if or in conditions) to do leave-one-out cross-validation (LOOCV)
 * The name is perhaps inaccurate: this code does no validation by itself; all it does is generate unbiased predictions;
 *  however the method is the standard CV method, so until someone complains the name is sticking.
 * to further reduce bias, consider passing shuffle.
 *
 * Example:
 *
 * . sysuse auto
 * . svm foreign headroom gear_ratio weight, type(c_svc) gamma(0.4) c(51)
 * . predict P
 * . gen err = foreign != P
 * . qui sum err
 * . di "Training error rate: `r(mean)'"
 * . drop P err
 * .
 * . cv P svm foreign headroom gear_ratio weight, folds(_N/3) shuffle  type(c_svc) gamma(0.4) c(51)
 * . gen err = foreign != P
 * . qui sum err
 * . di "Cross-validated error rate: `r(mean)'"
 *
 * You can use this with "unsupervised" estimators---ones which take no {help depvar} (y)---too.
 * cv passes whatever options you give it directly to the estimator; all it handles it the folding.
 *
 *
 * See also:
 *  {help gridsearch}
 *
 *
 * TODO:
 *  'if' and 'in'
 *  stratified folding
 *  maybe this should be called "cross_predict" because we don't actually do the validation...
 */

program define cv, eclass

  /* parse arguments */
  gettoken target 0 : 0
  gettoken estimator 0 : 0
  syntax varlist [if] [in], folds(int 5) [shuffle] [strata(string)] [*]

  confirm name `estimator'
  confirm new variable `target'
  confirm variable `varlist'

  qui count `if' `in'
  if(`folds'<=0 | `folds'>=`r(N)') {
    di as error "Invalid number of folds: `folds'. Must be between 1 and the number of active observations `r(N)'."
    exit 1
  }

  if("`strata'" != "") {
    confirm variable `strata'
    di as error "cv: stratification not implemented."
    exit 2
  }

  /* shuffling */
  if("`shuffle'"!="") {
    tempvar original_order
    tempvar random_order
    gen `original_order' = _n
    gen `random_order' = uniform()
    sort `random_order'
  }

  /* generate folds */
  // the easiest way to do this in Stata is simply to mark a new column
  // and stamp out id numbers into it
  // the tricky part is dealing with if/in
  // and the trickier (and currently not implemented) part is dealing with
  // stratification (making sure each fold has equal proportions of a categorical variable)
  tempvar fold
  if("`if'"!="" | "`in'"!="") {
    di as error "cv: if/in not yet implemented."
    exit 3
  }
  gen int fold = _n/`folds'
  // TODO: handle if/in
  //       this would be easy if I had an _n which was the index within the selected subset: just use that instead
  // I could write a loop, but that's slow. also i don't know how to mix if/in and loops

  // because shuffling can only affect which folds data ends up in,
  // immediately after generating fold labels we can put the data back as they were.
  // (i prefer rather do this early lest something later break and the dataset be mangled)
  // (this can't use snapshot or preserve because restoring those will erase `fold')
  if("`shuffle'"!="") {
    sort `original_order'
  }

  /* cross-predict */
  // We don't actually predict into target directly, because most estimation commands
  // get annoyed at you trying to overwrite an old variable (even if an unused region).
  // Instead we repeatedly predict into B, copy the fold into target, and destroy B.
  //
  // We don't actually create `target' until we have done one fold, at which point we *clone* it
  // because we do not know what types/labels the predictor wants to attach to its predictions,
  // (which can lead to strangeness if the predictor is inconsistent with itself)
  tempvar B
  foreach f = numlist 1/`folds' {
    // train on everything that isn't the fold
    `estimator' `varlist' if `fold' != `f', `options'
    // predict into the fold
    predict `B' if `fold' == `f'

    // on the first fold, *clone* B
    if(`f' == 1) {
      clone `target' `B' if 0
    }

    // save the predictions from the current fold
    replace `target' = `B' if `fold' == `f'
    drop `B'
  }

  /* clean up */
  // drop e(), because its contents at this point are only valid for the last fold
  // and that's just confusing
  ereturn clear
end

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


* added sema.do skeleton

* added sema.do skeleton

# sema executable

redo-ifchange config.base config

. ./config.base
. ./config

link

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


add cleanup rule

add cleanup rule

rm $( redo-targets | grep -v '^\.\.' | grep -v '^/' )

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


Clean version of do file for publication

/*
###############
Set Up:
###############

*/

clear
 cd "/Users/kevin/Desktop/PoliceAssaults"
 *No Federal Agencies, 0s if state had 0 for a year in assaults.
 insheet using "data/final/NonZero_NoFed_FinalData.csv"

 /*
 Other Options
 */
 /*
 *No Federal Agencies, but with NA's if states had 0 for a year in assaults.
 *insheet using "data/final/NoFed_FinalData.csv"
 *Federal Agencies, but with NA's if states had 0 for a year in assaults.
 insheet using "data/final/Fed_FinalData.csv"
 *Federal Agencies, 0s if state had 0 for a year in assaults.
 insheet using "data/final/NonZero_Fed_FinalData.csv"
 */
 *insheet using "data/final/FinalData_nofed2.csv"
 *insheet using "data/final/FinalData.csv"
 set more off

 run "do/variables.do"

 /*
 ###############
 Stata Time, Set Your TimeSeries
 ###############
 */
 xtset  stateName ov_correcttime

 *Drop Florida because it only reports in December (looks like full assaults).
 drop if state=="Florida"
 *Canal Zone and Puerto Rico and Virgin Islands have no assaults.
 drop if state=="Canal Zone"
 drop if state=="Puerto Rico"
 drop if state=="Virgin Islands"
 *drop if state=="Guam"
 *Did not report their crime rates properly.
 drop if state=="Alabama"
 drop if state=="Rhode Island"
 *DC only has One Purchase
 drop if state=="District of Columbia"
 drop if unemployrate==0
 drop if year==2015
 drop if year==2016

/*
####################################################################
*/
 count if ov_quantitybought > 0
 count if assaults != .
 count if assaults == 0

 tab state, nofreq
 display r(r)

 count if ov_quantitybought > 0
 count if assaults != .
 count if assaults == 0

 sum assaults
 sum vicrimepop
 sum popmillion
 sum officerper1000
 sum unemployrate
 sum black_perc
 sum lincome
 sum ov_clothing_quantity_hund
 sum ov_clothing_stockpile_hund
 sum ov_armor_quantity_hund
 sum ov_armor_stockpile_hund

 sum ov_weapons_stockpile_hund
 sum ov_record_quantity_hund
 sum ov_photo_stockpile_hund

 /*
 For Poster:

 Carriere, K. R., & Encinosa, W. (2017, June). The Militarization of Police: Evidence of Increased Citizen Conflict. Poster Presented at the Society for the Psychological Study of Social Issues Summer Conference, Alberqueque, NM.
 */
 /*
 sum ov_clothing_quantity
 sum ov_clothing_stockpile
 sum ov_armor_quantity
 sum ov_armor_stockpile
 sum ov_weapon_quantity
 sum ov_weapon_quantity_hund
 sum ov_photo_quantity
 sum ov_photo_stockpile

 xtnbreg assaults i.ov_correcttime c.l3_ov_clothing_stockpile_hund##c.l3_ov_clothing_stockpile_hund c.l3_ov_armor_stockpile_hund##c.l3_ov_armor_stockpile_hund c.l3_ov_weapons_stockpile_hund##c.l3_ov_weapons_stockpile_hund c.l3_ov_photo_stockpile_hund##c.l3_ov_photo_stockpile_hund  $controls, irr fe exposure(vicrimepop)
 margins, at(l3_ov_armor_stockpile_hund=(0(.25)21.5)) atmeans vsquish noatlegend
 marginsplot, plot1opts(mcolor("ltblue") msymbol("dh")) noci saving(file1, replace)
 xtnbreg assaultinjurytot i.ov_correcttime c.l6_ov_clothing_stockpile_hund##c.l6_ov_clothing_stockpile_hund c.l6_ov_armor_stockpile_hund##c.l6_ov_armor_stockpile_hund c.l6_ov_weapons_stockpile_hund##c.l6_ov_weapons_stockpile_hund c.l6_ov_photo_stockpile_hund##c.l6_ov_photo_stockpile_hund  $controls, irr fe exposure(vicrimepop)
margins, at(l6_ov_armor_stockpile_hund=(0(.25)21.5)) atmeans vsquish noatlegend
marginsplot, plot1opts(mcolor("cranberry") msymbol("sh")) noci saving(file2, replace)
 xtnbreg assaultinjurytot i.ov_correcttime c.l12_ov_clothing_stockpile_hund##c.l12_ov_clothing_stockpile_hund c.l12_ov_armor_stockpile_hund##c.l12_ov_armor_stockpile_hund c.l12_ov_weapons_stockpile_hund##c.l12_ov_weapons_stockpile_hund c.l12_ov_photo_stockpile_hund##c.l12_ov_photo_stockpile_hund  $controls, irr fe exposure(vicrimepop)
 margins, at(l12_ov_armor_stockpile_hund=(0(.25)21.5)) atmeans vsquish noatlegend
marginsplot, plot1opts(mcolor("midblue") msymbol("th")) noci saving(file3, replace)
combomarginsplot file1 file2 file3, ///
    labels("Three Month Lag" "Six Month Lag" "Twelve Month Lag") noci

marginsplot, plot1opts(mcolor("olive") lcolor("forest_green")) plot2opts(mcolor("khaki") lcolor("ltkhaki")) xtitle("Current Round") ytitle("Mean Amount Given to Partner") title("Model 1") noci
*/

/*
Table 1:
*/

pwcorr assaults vicrimepop popmillion officerper1000 unemployrate lincome black_perc l6_ov_clothing l6_ov_armor l6_ov_weapons l6_ov_photos, sig star(.05)

/*
Table 2:
Negative Binomials with 6 Month Lag
*/
xtnbreg assaultinjurytot i.ov_correcttime c.l6_ov_clothing_hund  c.l6_ov_armor_hund c.l6_ov_weapons_hund c.l6_ov_photos_hund $controls, irr fe exposure(vicrimepop)
xtnbreg assaultinjurytot i.ov_correcttime c.l6_ov_clothing_stockpile_hund c.l6_ov_armor_stockpile_hund c.l6_ov_weapons_stockpile_hund c.l6_ov_photo_stockpile_hund  $controls, irr fe exposure(vicrimepop)
xtnbreg assaultinjurytot i.ov_correcttime c.l6_ov_clothing_stockpile_hund##c.l6_ov_clothing_stockpile_hund c.l6_ov_armor_stockpile_hund##c.l6_ov_armor_stockpile_hund c.l6_ov_weapons_stockpile_hund##c.l6_ov_weapons_stockpile_hund c.l6_ov_photo_stockpile_hund##c.l6_ov_photo_stockpile_hund  $controls, irr fe exposure(vicrimepop)

/*
Table 3:
Negative Binomials with 12 Month Lag
*/
xtnbreg assaultinjurytot i.ov_correcttime c.l12_ov_clothing_hund  c.l12_ov_armor_hund c.l12_ov_weapons_hund c.l12_ov_photos_hund $controls, irr fe exposure(vicrimepop)
xtnbreg assaultinjurytot i.ov_correcttime c.l12_ov_clothing_stockpile_hund c.l12_ov_armor_stockpile_hund c.l12_ov_weapons_stockpile_hund c.l12_ov_photo_stockpile_hund $controls, irr fe exposure(vicrimepop)
xtnbreg assaultinjurytot i.ov_correcttime c.l12_ov_clothing_stockpile_hund##c.l12_ov_clothing_stockpile_hund c.l12_ov_armor_stockpile_hund##c.l12_ov_armor_stockpile_hund c.l12_ov_weapons_stockpile_hund##c.l12_ov_weapons_stockpile_hund c.l12_ov_photo_stockpile_hund##c.l12_ov_photo_stockpile_hund  $controls, irr fe exposure(vicrimepop)
/*
Table 4:
Negative Binomials with 3 Month Lag
*/
xtnbreg assaultinjurytot i.ov_correcttime c.l3_ov_clothing_hund  c.l3_ov_armor_hund c.l3_ov_weapons_hund c.l3_ov_photos_hund $controls, irr fe exposure(vicrimepop)
xtnbreg assaultinjurytot i.ov_correcttime c.l3_ov_clothing_stockpile_hund c.l3_ov_armor_stockpile_hund c.l3_ov_weapons_stockpile_hund c.l3_ov_photo_stockpile_hund  $controls, irr fe exposure(vicrimepop)
xtnbreg assaults i.ov_correcttime c.l3_ov_clothing_stockpile_hund##c.l3_ov_clothing_stockpile_hund c.l3_ov_armor_stockpile_hund##c.l3_ov_armor_stockpile_hund c.l3_ov_weapons_stockpile_hund##c.l3_ov_weapons_stockpile_hund c.l3_ov_photo_stockpile_hund##c.l3_ov_photo_stockpile_hund  $controls, irr fe exposure(vicrimepop)

/*
Other variables you're welcome to try:

Mean-centered everything with variables that have _c in them.

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


(misc) sample of bug ereturn post bug

(misc) sample of bug ereturn post bug

clear all
pr drop _all

cap pr drop myreg
pr define myreg, eclass
	args N
	qui reg price weight
	matrix b = e(b)
	matrix V = e(V)
	ereturn clear
	local depvar = "price"
	local df_r 999
	ereturn post b 	V , dep(`depvar') obs(`N') dof(`df_r')
end

sysuse auto, clear
set more off
myreg 1000000
ereturn list

myreg 1000001
ereturn list

exit

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


Add semi-clean.do

Add semi-clean.do

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


made a change

made a change

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


Added .ihlp sample for Stata.

Added .ihlp sample for Stata.

The author of this message, mwhite-IPA, is the source of this sample.

error: pathspec 'samples/Stata/include.ihlp' did not match any file(s) known to git


Create Country_SpecificQs.do

Create Country_SpecificQs.do

This program reads in the grand merge file and prints each country specific question code to the console

** this program reads in the grand merge file and prints each country specific question code to the console
** read the grand_merge file
use "C:\Users\zoorobmj\Desktop\grand_merge.dta"

* this loop will get every country specific question
** to instead find any particular country, delete outer loop and replace pais with number equal to pais of interest (line 13)
*** plausibly one could toggle with r(c) == [num] if you wanted to, say, find questions asked in <5 countries, etc
foreach i of num 1/17 21/29 40 41 {
	foreach var of varlist q1-q11nr {
		capture quietly tab `var' pais
		* I know it's country specific if r(c) == 1
		if r(c) == 1 {
		quietly sum `var' if pais == `i'
		* if it's ctry specific AND has results for Nicaragua, it is a Nicaragua-only question
			if r(N) > 0 {
				display "`var'"
				}
		}
	}
}

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


modelo de cointegracion

modelo de cointegracion

clear
*Cargar base de datos;
cd "C:\Users\rsanchez\Dropbox\Tesis_ITAM_RS"
use "tesisDB_anexo2"

*Establecer temporalidad
keep if ao>=2008 & ao<=2013
tsset year, format(%tmCY)

*Creacin de variables
gen lnhom=ln(homicidio)
gen lnrob=ln(robo)
gen Dhomicidio=D.homicidio
gen Dlnhom=D.lnhom

*Pre-anlisis grfico
	twoway (tsline homicidio) if ao>=2007
	qui tsline homicidio, name(f, replace)
	qui tsline D.homicidio, name(df, replace) yline(0)
	qui tsline robo, name(b, replace)
	qui tsline D.robo, name(db, replace) yline(0)
	qui tsline DD.homicidio, name(df, replace) yline(0)
	qui tsline DD.robo, name(db, replace) yline(0)
	graph combine f df b db, cols(2)
	graph combine f b, cols(1)

*i) Pruebas de raiz unitaria (I. Verificar que las variables son I(d) (Integrada de orden d) con d>0)
	dfuller homicidio
	dfuller robo
*ii) no podemos rechazar la hiptesis de raz unitaria. Verificamos que su orden de integracin sea el mismo:
	dfuller D.homicidio
	dfuller D.robo
		*La prueba Dickey-Fuller nos indica que ambas series son integradas de orden uno

* iii) Modelo Engle Granger de cointegracin
	regress robo homicidio
	predict Rhat, residual
*iv)  prueba Dickey-Fuller en residuales
		*Para asegurarnos que las variables estn co-integradas y que el modelo es apropiado se debe probar que los residuales son I(1)
	dfuller Rhat

	regress robo L.homicidio
	predict ehat, residual
	dfuller ehat

*v) ECM  Modelo de Correccin de Errore
	regress D.robo L.Rhat D.homicidio
	predict Recm, residual
	dfuller Recm
	twoway (tsline Recm)

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


(benchmark) Effect of increasing number of cores

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


fixed load and write

fixed load and write

program diffindiff2

// this stores variable names in as t1, t2, t3 and so on
local i = 5
while "``i''" != "" {
    local count = `i' - 4
    local t`count' = "``i''"
    di "var is `t`count''"
    local ++i
}

local var `1'
local varlabel `2'
local tabname `3'
local mode `4'

di "var: `var', tab: `tabname'"
di "in mode `mode'"

if "`mode'" == "run" {
    di "Running regressions"
    * run_reg `t1' `t2' `t3' `tabname' `var'

    local i = 1
    while "`t`i''" != "" {
        local t "`t`i''"
        di "running `t'"
        * run_reg `t1' `t2' `t3' `tabname' `var'
        local ++i
    }

}

if "`mode'" == "write" {
    di "Writing"
    est clear
    local i = 1
    while "`t`i''" != "" {
        local t "`t`i''"
        di "loading `t'"
        load_reg `t' `tabname' `var' `varlabel'
        local ++i
    }
    write_reg  `tabname' `var' `varlabel'
}

end

program load_reg

local t `1'
local tabname `2'
local var `3'

** est clear
** foreach x in `t1' `t2' `t3'{
estimates use ${myestimates}`tabname'_fips_`t'_`var'
estadd local unitfe "Yes", replace
estadd local monthfe "Yes", replace
eststo est`t'
*}
end

program run_reg

local t1 `1'
local t2 `2'
local t3 `3'
local tabname `4'
local var `5'

di "----"
di "var: `var', tab: `tabname'"
di "for `t1', `t2', `t3'"
di "----"

save ${stash}tmp, replace

foreach x in `t1' `t2' `t3'{
est clear

local command "xtpoisson `x' 1.treat#1.post 1.post#1.large 1.treat#1.post#1.large i.month"

di "now running for `t1'"
runcommand tmp "`command'" `tabname'_fips_`x'_`var'

}

end

program write_reg

local tabname `1'
local var `2'
local varlabel `3'

esttab using "${tables}`tabname'_fips_`var'.tex", keep(1.treat#1.post 1.post#1.`var' 1.treat#1.post#1.`var') coeflabels(1.treat#1.post#1.large "TIGER X POST X `varlabel'" 1.treat#1.post "TIGER X POST" 1.post#1.`var' "POST X `varlabel'" ) order(1.treat#1.post#1.large 1.treat#1.post 1.post#1.`var') se ar2 nonotes replace booktabs  s(unitfe monthfe N, label("County FE" "Month FE")) label

end

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


update shocks

update shocks

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

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

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

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

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

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

la var totShock "Total shocks"

* Create shock buckets
/* World Bank classifications
	Prices (inputs, outputs, food)
	Hazards (natural, droughts, floods)
	Employment (jobs, wages)
	Assets (house, land, livestock)
	Health (death, illness)
	Crime & Safety (theft, violence)	*/

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

g byte priceShk = inlist(h16q00, 106, 107) &  inlist(h16q01, 1) == 1
g byte hazardShk = inlist(h16q00, 101, 102, 103, 117) &  inlist(h16q01, 1) == 1
g byte employShk = inlist(h16q00, 108, 109) &  inlist(h16q01, 1) == 1
g byte assetShk = inlist(h16q00, 104, 105) &  inlist(h16q01, 1) == 1
g byte healthShk = inlist(h16q00, 110, 111, 112, 113) &  inlist(h16q01, 1) == 1
g byte crimeShk = inlist(h16q00, 114, 115, 116) &  inlist(h16q01, 1) == 1

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

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

* How did households cope?
label list df_SHOCKRECOVERY

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

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

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

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

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

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

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

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

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

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

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


Stata code that creates .dta file for 2014 BETOS

******************************************************
* Purpose: Read in  2014 BETOS text file, save as .dta
* Date: 8-Jul-2016
* Author: Christina Charlesworth
******************************************************

* read in file from CHSE github
infix str cpt 1-5 str betos 7-9 str enddate 10-17 using "https://raw.githubusercontent.com/chse-ohsu/PublicUseData/master/BETOS/betpuf14/betpuf14.txt", clear

* generate aggregate category variable
gen facBetos = "E & M" if (regexm(betos, "^M"))
replace facBetos = "Procedures" if (regexm(betos, "^P"))
replace facBetos = "Imaging" if (regexm(betos, "^I"))
replace facBetos = "Tests" if (regexm(betos, "^T"))
replace facBetos = "DME" if (regexm(betos, "^D"))
replace facBetos = "Other" if (regexm(betos, "^O"))
replace facBetos = "Except./unclass." if (regexm(betos, "^Y") | regexm(betos, "^Z"))

* save to shared drive
save "E:\Share\LookupTablesAndCrosswalks\BETOS\betpuf14\betpuf14.dta"

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


Added stata code to get effect per subgroup from regression

** Untested but should work **

sysuse auto
regress price c.weight##i.foreign##i.rep78

** Lets get the slope between weight and price within each foreign*rep78 subgroup.
margins, dydx(weight) over(foriegn rep78)

** To get pairwise comparisons:
margins, dydx(weight) over(foriegn rep78) pwcompare

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


first commit

first commit

Data/Calibration/ConsumptionParameters/Consumption Calibration (Tatenda- March Do-file).do

/bin/sh: 1: Syntax error: "(" unexpected


Even better tree

Even better tree

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/dreameater89/d3_testing.git/'


clockseed: set the Stata rng seed from the clock.

Otherwise *the seed is constant*, which is so absurd.

program define clockseed
  set seed `= mod(clock("$S_DATE $S_TIME","D M 20Y hms"),2^31)'
end

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


"Unit test" for not mixing SVR and "prob"

* predict_svr.do

sysuse auto
capture svm price mpg-gear_ratio if !missing(rep78), type(nu_svr) kernel(sigmoid) probability
if(_rc == 0) {
  di as error "svm should disallow regression with probability turned on"
  exit 1
}

error: pathspec 'src/tests/train_svr_prob.do' did not match any file(s) known to git


new ado for running DD models

new ado for running DD models

local dv "numcontrib numuser numnewusers numnewusers6 numnewusers90 numserious90"
local cutoffs "2011 2012 2013 2014"

// this runs the regressions
foreach y in `cutoffs'{
    foreach x in `dv'{
        shell ./batchreg.sh panelfips xtpoisson `x' fips `x' run
    }
}

foreach x in `dv'{
   shell ./batchreg.sh panelfips xtreg `x' fips 2014 run
}

// this loads and writes the regressions to tex

foreach y in `cutoffs'{
    diffindiff xtpoisson "`dv'" fips `y' write

}

diffindiff xtreg "`dv'" fips 2014 write

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


basic version complete

basic version complete

program kingcounty

makedata
makedv_county
balancepanel_county

end

program run_reg

sort unitid month
format firstm %tm

bysort istiger month: egen newadded = total(month==firstmonth)
bysort istiger month: egen numupdated = total(numchanges>0)
bysort istiger month: egen avgattr = mean(hasattr)

bysort istiger month: gen tag = (_n==1)

gen newa_tiger = sum(newadd * (istiger==1)*(tag==1))
gen newa_control = sum(newadd * (istiger==0)*(tag==1))
gen newa_sum = .
replace newa_sum = newa_tiger if ist == 1
replace newa_sum = newa_control if ist == 0
drop newa_ti newa_cont

gen percentupdated = numupd / newa_sum

list newadd newa_ numupd month istiger if month == 621 & tag == 1

local var newa
local var newa_sum
local var numupd
local var avgattr
local var percentup

replace `var' = 1200 if `var' > 1200

tw (connected `var' month if istiger == 0 & tag==1) (connected `var' month if istiger == 1 &tag==1), legend(order(2 "TIGER Counties" 1 "Control Counties" ))

graph export ${tables}tmp1.eps, replace

codebook

end

program makedv_county

**use ${stash}king_tmp, clear
use ${stash}ca_tmp, clear

keep if highwayclass == 3

**bysort highwayid: egen mixtiger = mean(istiger)

bysort highwayid month: gen numchanges = _N
bysort highwayid month: egen maxattrib = max(hasattrib)
bysort highwayid: gen firstmonth = month[1]

end

program balancepanel_county

bysort highwayid month: drop if _n > 1
drop unitid
gen unitid = highwayid

tsset unitid month
tsfill, full

local outcomes "numchanges maxattrib"

foreach x in `outcomes'{
    replace `x' = 0 if `x' == .
}

local covars "istiger firstmonth name hasattr"

foreach x in `covars'{
    gsort unitid month
    bysort unitid: carryforward `x', gen(tmp1)
    gsort unitid -month
    bysort unitid: carryforward tmp1, gen(tmp2)
    replace `x' = tmp2
    drop tmp1 tmp2
    di "finished `x'"
    di "---"
}

end

program makedata

use ${stash}mergemaster_way, clear

// control: fresno == 06019
// control: santa clara = 06085 / 1.8 million

// control: madera = 06039
// treat : merced = 06047

// treat: stanislaus = 06099
// treat: san joaquin = 06077 / pop 702k

keep if (fips == "06039" | fips == "06047")

egen highwayid = group(name)
replace highwayid = . if ishighway == 0
replace highwayid = . if name == "NA"
drop if highwayid == .

**save ${stash}king_tmp, replace
save ${stash}ca_tmp, replace

end

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


Update and rename Stata to Stata/XX_GeographicInfo.do

/*-------------------------------------------------------------------------------
# Name:		XX_GeographicInfo
# Purpose:	Tidy up geographic information, export to R and jitter GPS for mapping
# Author:	Tim Essam, Ph.D.
# Created:	10/31/2014; 02/19/2015.
# Owner:	USAID GeoCenter | OakStream Systems, LLC
# License:	MIT License
# Ado(s):	see below
#-------------------------------------------------------------------------------
*/

* Bring in geographic data

use "$pathraw/GSEC1.dta", clear

* Tidy up some of the string variables
replace h1aq1 = upper(h1aq1)
replace h1aq2 = upper(h1aq2)

label drop sregion
label def sregion 1 "Kampala" 2 "Central-1" 3 "Central-3" 4 "East-Central" /*
*/ 5 "Eastern" 6 "Mid-North" 7 "North East" 8 "West Nile" 9 "Mid-West" 10 "South-Western"
label values sregion sregion

decode sregion, gen(subRegion)

* Merge in the geovariable information for exportin to R

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


Start CUI based evaluation

Start CUI based evaluation

#!/usr/bin/env python3
from collections import OrderedDict, defaultdict
from pathlib import Path
import os
import json
import yaml
import re
import redo
redo.ifchange('comap.py'); import comap

project = redo.base
project_path = Path('projects') / project

with redo.ifchange(evaluation_config=project_path / 'evaluation-config.yaml',
                   max_recall_evaluation='{}.maximum-recall.evaluation.yaml'.format(project),
                   baseline_evaluation='{}.baseline.evaluation.yaml'.format(project)) \
        as files:
    evaluation_config = yaml.load(files['evaluation_config'])
    max_recall_evaluation = yaml.load(files['max_recall_evaluation'])
    baseline_evaluation = yaml.load(files['baseline_evaluation'])

outcome_ids = evaluation_config['outcome_ids']

class Variant(object):

    def vary(self, generated, reference):
        """Compute a variation of the generated CUIs."""
        return generated

def create_result(generated, reference, variant, outcome_id):

    generated = variant.vary(generated, reference)

    confusion = comap.confusion_matrix(generated, reference)
    measures = comap.measures(generated=generated, reference=reference)
    return OrderedDict([
        ('confusion', confusion),
        ('measures', measures),
    ])

def create_results(generated, references, variants, outcome_ids):
    res = OrderedDict([
        ('by-variant', OrderedDict())
    ])
    for variant_id, variant in variants.items():
        res_for_variant = res['by-variant'][variant_id] = OrderedDict([
            ('by-outcome', OrderedDict())
        ])
        for outcome_id in outcome_ids:
            res_for_outcome = create_result(generated[outcome_id], references[outcome_id], variant, outcome_id)
            res_for_variant['by-outcome'][outcome_id] = res_for_outcome
    return res

variants = OrderedDict([
    ('baseline', Variant())
])

generated = OrderedDict([
    (outcome_id, value['generated-cuis'])
    for outcome_id, value in baseline_evaluation['by-outcome'].items()
])

references = OrderedDict([
    (outcome_id, value['generated-cuis'])
    for outcome_id, value in max_recall_evaluation['by-outcome'].items()
])

result = create_results(generated, references, variants, outcome_ids)

with redo.output() as f:
    yaml.dump(result, f)

error: pathspec 'evaluation/default.cui-evaluations.yaml.do' did not match any file(s) known to git


Comit Code

Comit Code

clear all
set more off

use C:\Users\User\Desktop\300297683\Claudia\Documents\Magar\Seminario\Edomex17.dta

merge 1:1 seccion using "C:\Users\User\Desktop\300297683\Claudia\Documents\Magar\Seminario\Edomex12.dta"
keep if _merge == 3
drop _merge

save "C:\Users\User\Desktop\300297683\Claudia\Documents\Magar\Seminario\Edomex17.dta", replace

gen ceros = o
replace ceros = 1 if Distrito17 == 1
tab Distrito12 if ceros == 1

*identificar el viejo distrito que mas secciones le dio al nuevo*
* c = secciones que comparte, n = secciones del nuevo distrito, p = seeciones del distrito padre
* s= c/ p+n-c*

gen unos = 1
bysort Distrito12 dis4015100: egen c = sum(unos)

preserve
duplicates drop Distrito12 dis4015100, force
restore

bysort dis4015100: egen max = max(c)

bysort dis4015100: egen nuevo = count(seccion)
bysort Distrito12: egen padre = count(seccion)

gen padre1 = .
replace padre1 = 130 if dis4015100 == 1
replace padre1 = 91 if dis4015100 == 2
replace padre1 = 139 if dis4015100 == 3
replace padre1 = 75 if dis4015100 == 4
replace padre1 = 104 if dis4015100 == 5
replace padre1 = 92 if dis4015100 == 6
replace padre1 = 105 if dis4015100 == 7
replace padre1 = 95 if dis4015100 == 8
replace padre1 = 81 if dis4015100 == 9
replace padre1 = 81 if dis4015100 == 10
replace padre1 = 90 if dis4015100 == 11
replace padre1 = 296 if dis4015100 == 12
replace padre1 = 210 if dis4015100 == 13
replace padre1 = 210 if dis4015100 == 14
replace padre1 = 135 if dis4015100 == 15
replace padre1 = 122 if dis4015100 == 16
replace padre1 = 254 if dis4015100 == 17
replace padre1 = 296 if dis4015100 == 18
replace padre1 = 254 if dis4015100 == 19
replace padre1 = 133 if dis4015100 == 20
replace padre1 = 135 if dis4015100 == 21
replace padre1 = 118 if dis4015100 == 22
replace padre1 = 184 if dis4015100 == 23
replace padre1 = 194 if dis4015100 == 24
replace padre1 = 279 if dis4015100 == 25
replace padre1 = 184 if dis4015100 == 26
replace padre1 = 188 if dis4015100 == 27
replace padre1 = 227 if dis4015100 == 28
replace padre1 = 279 if dis4015100 == 29
replace padre1 = 289 if dis4015100 == 30
replace padre1 = 98 if dis4015100 == 31
replace padre1 = 289 if dis4015100 == 32
replace padre1 = 114 if dis4015100 == 33
replace padre1 = 98 if dis4015100 == 34
replace padre1 = 192 if dis4015100 == 35
replace padre1 = 242 if dis4015100 == 36
replace padre1 = 242 if dis4015100 == 37
replace padre1 = 187 if dis4015100 == 38
replace padre1 = 244 if dis4015100 == 39
replace padre1 = 167 if dis4015100 == 40
replace padre1 = 187 if dis4015100 == 41
replace padre1 = 115 if dis4015100 == 42
replace padre1 = 146 if dis4015100 == 43
replace padre1 = 146 if dis4015100 == 44
replace padre1 = 104 if dis4015100 == 45

gen aux1 = padre1 + nuevo - max
gen s = max/aux1

error: pathspec 'mapasComparados/loc/code/CodigoIndexSimClaudia.do' did not match any file(s) known to git


new stata file

new stata file

insheet using goodtiles.csv, clear

gen x_tmp = round(xmin, .1)
gen y_tmp = round(ymin, .1)

gen tilename = string(x_tmp) + " / " + string(y_tmp)

save goodtiles, replace

insheet using us1.csv, clear

gen x_tmp = 0.1 * floor(lon/0.1)
gen y_tmp = 0.1 * floor(lat/0.1)

gen tilename = string(x_tmp) + " / " + string(y_tmp)

merge m:1 tilename using goodtiles

outsheet id lon lat x_tmp y_tmp _merge using tmp.csv if _m !=2, replace

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


add file, merge master data set

add file, merge master data set

Added an example file that will be linked to from Master_Data_Set
article.

error: pathspec 'Topics/Master' did not match any file(s) known to git
error: pathspec 'Data' did not match any file(s) known to git
error: pathspec 'Set/stringMergeWithMasterDataSets.do' did not match any file(s) known to git


Forgotten file

Forgotten file

* settings.do
* make all platforms consistent in their batch output;
* tip buried in http://web.standford.edu/group/ssds/cgi-bin/drupal/files/Guides/Stata_Unix__2011.pdf*/
* NOTE: this is autoincluded to all tests via makefile magic
set linesize 119

error: pathspec 'src/tests/helpers/settings.do' did not match any file(s) known to git


ieddtable : file to test ieddtable during dev

	/* Create some dummy datat */

	clear all

	sysuse census

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

/*
	*Include this to see how the command test for non dummy values in dummies
	replace t = 2 if _n == 1
*/

/*
	*Include this to see how the command test that there are too few groups
			replace tmt = 0
	bys t : replace tmt = 1 if _n == 1
*/

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

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

	local outvars death //marriage divorce

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

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


Adding install target.

Adding install target.

redo-ifchange redo
sudo install -s redo /usr/local/bin
sudo ln -sf /usr/local/bin/redo /usr/local/bin/redo-ifchange

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


Fix test 130: ls -l output is not always as expected

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


iematch :  seedok help file

iematch :  seedok help file

Added the seedok option to the help file

{smcl}
{* }{...}
{hline}
help for {hi:iematch}
{hline}

{title:Title}

{phang2}{cmdab:iematch} {hline 2} Matching base observations towards target observations using on a single continous variable.

{title:Syntax}

{phang2}
{cmdab:iematch}
, {cmdab:grp:dummy(}{it:varname}{cmd:)} {cmdab:match:var(}{it:varname}{cmd:)}
[{cmdab:id:var(}{it:varlist}{cmd:)} {cmdab:m1} {cmdab:maxdiff(}{it:numlist}{cmd:)} {cmd:seedok}
{cmdab:matchid:name(}{it:string}{cmd:)} {cmdab:matchdi:ffname(}{it:string}{cmd:)}
{cmdab:matchre:sultname(}{it:string}{cmd:)} {cmdab:matchco:untname(}{it:string}{cmd:)}
]

{marker opts}{...}
{synoptset 22}{...}
{synopthdr:options}
{synoptline}
{synopt :{cmdab:grp:dummy(}{it:varname}{cmd:)}}The group dummy variable where 1
	indicates base observations and 0 target observations{p_end}
{synopt :{cmdab:match:var(}{it:varname}{cmd:)}}The variable with a continous value
	to match on{p_end}
{synopt :{cmdab:id:var(}{it:varlist}{cmd:)}}The uniquely and fully identifying ID
	varaible. Used to indicate which target observation a base observation is match
	with. If omitted an ID variable will be created.{p_end}
{synopt :{cmdab:m1}}Allows many-to-one matches. The default is to allow only
	one-to-one matches. See the {help iematch##desc:description} section.{p_end}
{synopt :{cmdab:maxdiff(}{it:numlist}{cmd:)}}Set a maximum difference allowed in
	{cmdab:matchvar()}. If a base observation has no match within this difference
 then it will remain unmatched{p_end}
{synopt :{cmd:seedok}}Supresses the error maessage thrown when there are duplicates
	in {cmd:matchvar()}. When there are duplicates, the seed needs to be set in order
	to have a replicable match. The {help seed} should be set before this command.{p_end}
{synopt :{cmdab:matchid:name(}{it:string}{cmd:)}}Manually sets the name of the
	variable that indicates which target observation each base observation is
	matched with. The default is _matchID{p_end}
{synopt :{cmdab:matchdi:ffname(}{it:string}{cmd:)}}Manually sets the name of the
	variable that indicates the differnece in {cmdab:matchvar()} in each match
	pair/group. The default is _matchDiff{p_end}
{synopt :{cmdab:matchre:sultname(}{it:string}{cmd:)}}Manually sets the name of
	the variable that indicates if an observation was matched, or provide a reason why
	it was not. The default is _matchOrReason{p_end}
{synopt :{cmdab:matchco:untname(}{it:string}{cmd:)}}Manually sets the name of the
	variable that indicates how many observations a target obsersvation is matched
	with in a many-to-one matches. The default is _matchCount{p_end}
{synoptline}

{marker desc}
{title:Description}

{pstd}{cmdab:iematch} matches base observations towards target observations in terms
	of nearest value in {cmd:matchvar()}. Base observations are observations with
	value 1 in {cmd:grpdummy()} and target observations are observations with value
	0. For example, in a typical p-score match, base observations are treatment and
	target is control, however, there are many other examples of matching where it could
	be different.

{pstd}{cmdab:iematch} base its matching algorithm on the Stable Marriage algorithm.
	This algorithm was chosen because it always a solution and because it was possible
	to implement a stable matching even if multiple observations has identical match
	values (see {cmd:seed()} option for more details). One disadvantage is of this
	algorithm is that it only take local efficiency into account and not global. This
	means that it is possible that other matching algorithms might generate a more
	efficient match in terms of the sum of the difference of all matched pairs/groups.

{pstd}{hi:{ul:One-to-one matching algorithm}}{break}
	The algorithm used in a one-to-one match starts by evaluating which
	target observation each base observation is closest to and vice versa for
	target observations. If a base and a target observation pair mutually prefer
	each other, then those two observations are a match. The algorithm then repeats
	these two steps but excludes observations after they are matched until all base
	observations are either matched or excluded due to the option {cmdab:maxdiff()}.
	Matched observations ends up in pairs of exactly one base observation and one
	target observation.

{pstd}In a one-to-one match there have to be at least as many target observations
	as there are base observation. A one-to-one match returns three variables. One
	variable indicates the result of the matching for each observation. For example,
	matched, not matched, no match within the max difference etc. The other two variables
	hold info on the matched pair. One variable is the ID of the target observation
	in the match pair, and the other variable is the difference in {cmd:matchvar()}
	between the two observation in the match pair. See the below in this section
	for more details on the variables generated.

{pstd}{hi:{ul:Many-to-one matching algorithm}}{break}
	The algorithm used here is the same as in a one-to-one match. But instead
	of matching only when there is mutual preference, all base observations are
	matched towards their preferred target observation in the first step, as long
	as the match is within the max-value if {cmdab:maxdff()} is used. Matched observations
	end up in groups in which there is exactly one target observation but where there are
	either one or several base observations.

{pstd}In a many-to-one match there is no restriction in terms of the number of
	target observations in relation to base observations. The many-to-one matching
	results in four variables. Three of the variables are the same as in a one-to-one
	match. The fourth variable indicates how many base observations that were matched
	towards each target observation. See the below in this section for more details on
	the variables generated.

{pstd}{hi:{ul:Variables generated}}{break}
	This section explains the variables that are generated by this command. All variables
	will be referred to by their default names, but those names can be manually set to somthing
	else using the corresponding options.

{pstd}{hi:_matchID}{break}
	This variable indicates the ID if the target observations in each match pair/group. For matched
	target observations, the value in this variable will be the same value as in teh ID
	variable. Since the values in the ID varaible are unique and there is exactly one target
	observation in each matched pair/group, this variable function as a unique pair/group ID.
	In addition to indicating which observations are included in the same pair/group, this
	varaible can be used to include a pair/group fixed effect in a regression.

{pstd}{hi:_matchDiff}{break}
	This variable indicates the difference in {cmd:matchvar()} between matched base observations
	and target observations. In a one-to-one match this value is the identical for
	both the base observation and the target observation in each matched pair.
	In a many-to-one match, this value is only indicated for base observations. It is
	missing for target observations as there are potentially multiple matches,. and
	then there are not one single difference.

{pstd}{hi:_matchOrReason}{break}
	This variable indicates the result of the match for all observations. Observations
	that ended up in a match pair or group has the value 1. Target observations
	not matched has the value 0. Any base observation without a valid match due to {cmdab:maxdff()} are
	assigned the value .n with a descriptive label. Any observations excluded from the match completely,
	either by having a missing value in {cmd:grpdummy()} or by using {inp:if} or {inp:in} are
	assigned the value .m and a descriptive label.

{pstd}{hi:_matchCount}{break}
	In a many-to-one match, this variable indicates how many target observations were
	matched towards each matched base observation. This variable can be used as regression
	weights when controlling for the fact that some observations are matched towards multiple
	observations.

{marker optslong}
{title:Options}

{phang}{cmdab:grp:dummy(}{it:varname}{cmd:)} indicates which variable is the group
	dummy. This variable, must be numeric and is only allowed to have the values 1,
	0 or missing. 1 indicates a base observation, 0 indicates a target observation,
	and observations with a missing value will be excluded from the missing.

{phang}{cmdab:match:var(}{it:varname}{cmd:)} indicates the variable used in the
	matching. This must be a numeric variable, and it is typically a continuous
	variable. This variable must not be missing for any observations that has
	either the value 1 or 0 in the group dummy variable.

{phang}{cmdab:id:var(}{it:varlist}{cmd:)} indicates the variable that uniquely
	and fully identifies the data set. The values in this variable is the values
	that will be used in the variable that indicates which target observation each
	base observations matched against.

{phang}{cmdab:m1} set the match to a many-to-one match. This allows multiple base
	observations to be matched towards a single target observation. The default is
	a one-to-one match when each matched target observation only is mathced towards
	a single base observation. This option allows the number of base observations
	to be larger then the number of target observations. See {help iematch##desc:description}
	section for more details.

{phang}{cmdab:maxdiff(}{it:numlist}{cmd:)} sets a maximum allowed difference between
	a base observation and a target observation for a match to be valid. Any base
	observation without a match within this difference will end up unmatched.

{phang}{cmd:seedok} supresses the error maessage thrown when there are duplicates among
	the base observations or the target observations in {cmd:matchvar()}. When there
	are duplicates a random variable is used to distinguish which variable to match.
	Setting the seed makes this randomization replicable meaning that the matching
	is replicable. The {help seed} should be set before this command by the user. When the
	seed is set, or if replicable matching is not important, then the option {cmd:seedok} can
	be used to supress the error message. Duplicates between base observations and
	target observations are allowed.

{phang}{cmdab:matchid:name(}{it:string}{cmd:)} allows the user to manually set the
	name of the variable that indicates the target observations in each match pair/group.
	If omitted, the default name is {inp:_matchID}. The names {inp:_ID}, {inp:_matchDiff}, {inp:_matchOrReason}
	and {inp:_matchCount} are not allowed.

{phang}{cmdab:matchdi:ffname(}{it:string}{cmd:)} allows the user to manually set
	the name of the variable that indicates the difference between the matched base observations
	and target observations. If omitted, the default name is {inp:_matchDiff}. The
	names {inp:_ID}, {inp:_matchID}, {inp:_matchOrReason} and {inp:_matchCount} are
	not allowed.

{phang}{cmdab:matchre:sultname(}{it:string}{cmd:)} allows the user to manually set the
	name of the variable that indicates the result of the match for each observation.
	If omitted, the default name is {inp:_matchOrReason}. The names {inp:_ID},
	{inp:_matchID}, {inp:_matchDiff} and {inp:_matchCount} are not allowed.

{phang}{cmdab:matchco:untname(}{it:string}{cmd:)} allows the user to manually set the
	name of the variable that indicates the number of base observations that has
	been matched towards each matched matcehd target observation. This option may
	only be used in combination with option {cmd:m1}. If omitted, the default
	name is {inp:_matchCount}. The names {inp:_ID}, {inp:_matchID}, {inp:_matchDiff}
	and {inp:_matchOrReason} are not allowed.

{title:Author}

{phang}Kristoffer Bj�rkefur, The World Bank, DECIE

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

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

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


iekdensity: adding run folder and test do-file

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

	* Add the path to your local clone of the [ietoolkit] repo
	global 	ietoolkit "C:/Users/WB527265/Documents/GitHub/ietoolkit"
	qui		do 		  "${ietoolkit}/src/ado_files/iekdensity.ado"

	* Load data
	sysuse	auto, clear

	* Generate treatment variables
	gen		random 		 	  = runiform()
	sort  	random
	gen     treatment_binary  = random > 0.5
	tab	    treatment_binary

	* Generate factor variables
	forv    factorCap = 3/6 {

		gen treatment_factor`factorCap' = ceil(`factorCap' * _n/_N)
		tab treatment_factor`factorCap'
	}

/*******************************************************************************
	No error
*******************************************************************************/

	* Binary treatment
	* ----------------
	iekdensity price, treatvar(treatment_binary )

	** Color options
	iekdensity price, treatvar(treatment_binary ) color(eltblue edkblue)

	* Add label to treatment
	lab def 		  		 					  treatLab 0 "Control" 1 "Treatment"
	lab val 				   treatment_binary   treatLab

	iekdensity price, treatvar(treatment_binary ) color(eltblue edkblue)

	** Statistic options
	iekdensity price, treatvar(treatment_binary ) stat(p50)

	* Add statistic with detailed style
	iekdensity price, treatvar(treatment_binary ) stat(mean) statstyle(lpattern(dashed) lwidth(2))

	** Effect options
	iekdensity price, treatvar(treatment_binary ) stat(p50) color(eltblue edkblue) effect

	* Specify control value
	iekdensity price, treatvar(treatment_binary) stat(p50) color(eltblue edkblue) effect control(0)
	iekdensity price, treatvar(treatment_binary) stat(p50) color(eltblue edkblue) effect control(1)

	* Add effect note with specified format
	iekdensity price, treatvar(treatment_binary ) stat(p50) color(eltblue edkblue) effect effectformat(%9.0fc)

	** Regression options

	** Kernel options

	** Graphic options
	iekdensity price, treatvar(treatment_binary ) stat(p50) color(eltblue edkblue) effect effectformat(%9.0fc) gr(graphregion(color(white)))

	* Categorical treatment
	* ---------------------
	iekdensity price, treatvar(treatment_factor3)
	iekdensity price, treatvar(treatment_factor4)
	iekdensity price, treatvar(treatment_factor5)
	iekdensity price, treatvar(treatment_factor6)

	iekdensity price, treatvar(treatment_factor3) color(eltblue midblue edkblue)

	iekdensity price, treatvar(treatment_factor3) stat(mean)

	iekdensity price, treatvar(treatment_factor3) color(eltblue midblue edkblue) effect

/*******************************************************************************
	Yes error
*******************************************************************************/

	* Change only one color
	iekdensity price, treatvar(treatment_binary)  color(eltblue)

	* Non-existing code as control
	iekdensity price, treatvar(treatment_binary)  control(3)

	* Too many colors
	iekdensity price, treatvar(treatment_binary)  color(eltblue midblue edkblue)

	* Not enough colors
	iekdensity price, treatvar(treatment_factor3) color(eltblue midblue) stat(mean)

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


iedropone : intiate first file

iedropone : intiate first file

Initiated a command that makes sure that you only drop one observation
at the time. Good with dynamic data flows.

	capture program drop 	iedropone
			program define 	iedropone ,

	qui {

		*noi di "command OK!"

		syntax [if] ,  [multivar(varname) multical(string)]

		*noi di "syntax OK!"

		version 11.0

		di "`if'"

		count `if'

		if `r(N)' == 1 {

			drop `if'

			noi di "1 observation dropped"

		}
		else {

			noi di "No observation dropped"

		}

	}

	end

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


interim commit

interim commit

use ${stash}panelfips, clear

gen popdens = (cntypop / aland_sqmi)

local vars "cntypop popdens emp_earnings percent_white age_median educ_college"

local outcomes "numuser"
local num "50"
bysort fips: gen tag = (_n==1)
gen tmp = .

foreach x in `vars'{
    di "`x'"
    egen p`num' = pctile(`x') if tag == 1, p(`num')
    gen p_tmp = (`x' > p`num')
    bysort fips: egen p`num'_`x' = max(p_tmp)
    drop p`num' p_tmp
}

program drop diffindiff2
foreach x in `vars'{
    diffindiff2 p`num'_`x' AboveMedian hetero1 run `outcomes'
}

est clear
foreach x in `vars'{
    di "`x'"
    load_reg numuser hetero1 p`num'_`x'
    di "-----------"
}

write_reg

program run_reg

local var `1'
replace tmp = `var'

est clear
eststo: xtpoisson numuser 1.post##1.treat##1.tmp i.year, fe vce(robust)
estimates save ${myestimates}hetero1_`var', replace

end

program load_reg

local t `1'
local tabname `2'
local var `3'

di "`t', `var'"
local bb "${myestimates}`tabname'_fips_`t'_`var'"
di "`bb'"
estimates use ${myestimates}`tabname'_fips_`t'_`var'
estadd local unitfe "Yes", replace
estadd local monthfe "Yes", replace
eststo est`var'
end

program write_reg

local var tmp

esttab using "${tables}hetero1.tex", keep(1.treat#1.post 1.post#1.`var' 1.treat#1.post#1.`var' 1.post) order(1.treat#1.post#1.`var' 1.treat#1.post 1.post#1.`var' 1.post) se ar2 nonotes replace booktabs  s(unitfe monthfe N N_g, label("County FE" "Month FE" "N" "Clusters")) coeflabels(1.treat#1.post#1.`var' "TIGER X POST X AboveMedian" 1.treat#1.post "TIGER X POST" 1.post#1.`var' "POST X AboveMedian" 1.post "Post") mtitles("Population" "Pop. Density" "Earnings" "PercentWhite" "Age" "College" "" )

end

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


send file to MT for processing

send file to MT for processing

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


Add iematch test file to branch

Add iematch test file to branch

This file was developed in the matchIE repo in kbjarkefur's private
account. This will be included in this branch from now on

	clear

	*command starts here

	cap program drop 	iematch
	    program define	iematch

		syntax  , GRPdummy(varname) MATCHcont(varname) [idvar(varname)]

		qui {

		if "`idvar'" == "" {

			gen _ID = _n

			local idvar _ID

		}

		tempvar hi_diff lo_diff pref match newMatch

		gen `hi_diff' = .
		gen `lo_diff' = .
		gen _matchDiff = .
		gen `pref' = .
		gen byte `match' = 0
		gen byte `newMatch' = 0
		gen _matchID = .

		*order `idvar' , after(`pref')

		**match loop

		count if `grpdummy' == 1 & `match' == 0
		local left2Match = `r(N)'

		pause on

			while (`left2Match' > 0) {

				sort `match' `matchcont'

				replace `lo_diff' 	= .
				replace `hi_diff' 	= .
				replace `pref'		= . if `match' == 0
				replace `newMatch' 	= 0

				replace `lo_diff' = abs(`matchcont' - `matchcont'[_n-1]) if `match' == 0 & `grpdummy' != `grpdummy'[_n-1]
				replace `hi_diff' = abs(`matchcont' - `matchcont'[_n+1]) if `match' == 0 & `grpdummy' != `grpdummy'[_n+1]

				replace `pref' = `idvar'[_n-1] if `match' == 0 & `lo_diff' <  `hi_diff'
				replace `pref' = `idvar'[_n+1] if `match' == 0 & `lo_diff' >= `hi_diff'

				replace `newMatch' = 1 if `match' == 0 & `pref' == `idvar'[_n-1] & `pref'[_n-1] == `idvar'
				replace `newMatch' = 1 if `match' == 0 & `pref' == `idvar'[_n+1] & `pref'[_n+1] == `idvar'

				replace `match' = 1 							if `newMatch' == 1
				replace _matchDiff = min(`lo_diff', `hi_diff') 	if `newMatch' == 1
				replace _matchID = `idvar' 						if `newMatch' == 1 & `grpdummy' == 1
				replace _matchID = `pref' 						if `newMatch' == 1 & `grpdummy' == 0

				*order _match* , last

			noi	count if `grpdummy' == 1 & `match' == 0
				local left2Match = `r(N)'

				*pause

			}
		}

	end

	set seed 1235324

	set obs 10000

	gen id = _n

	gen rand1 = uniform()

	gen tmt = (rand1 < .40)

	drop rand1
	tab tmt

	gen p_hat = uniform()

	iematch   , grp(tmt) match(p_hat) idvar(id)

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


iefolder test input 2 many words

iefolder test input 2 many words

cap program drop 	iefolder
	program define	iefolder

	syntax anything, projectfolder(string) [abb(string)]

	***Todo
	*Test that a folder called DataWork already exist (unless new project)
	*Test that old master do file exist
	*allow to specifiy other place for master do file

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

		Parse input

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

	gettoken subcommand item : anything

	gettoken itemType itemName : item

    gettoken itemName nothing : itemName

	local subcomand = trim("`subcommand'")
	local itemType 	= trim("`itemType'")
	local itemName 	= trim("`itemName'")

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

    if "`itemType'" != "" {

      di as error "you have specified to many words"
      error 198
    }
	 /***************************************************

		Test input

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

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

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

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

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

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

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

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

	}

	di "All tests ok"

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

		Start making updates to the project folder

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

	*Create a temporary textfile
	tempname 	newHandle
	tempfile	newTextFile

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

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

		di "Subcommand: New"

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

			di "ItemType: Project"
			iefolder_newProject "`projectfolder'" `newHandle'
		}
		*Creating a new round
		else if "`itemType'" == "round" {

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

			di "ItemType: round"
			iefolder_newRound `newHandle' "`itemName'" "`abb'"
		}
		*Creating a new master data set
		else if "`itemType'" == "master" {

			di "ItemType: master"
			iefolder_newMaster
		}
		*Creating a new monitor
		else if "`itemType'" == "monitor" {

			di "ItemType: monitor"
			iefolder_newMonitor
		}
	}

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

	*Copy the new master dofile from the tempfile to the original position
	copy "`newTextFile'"  "$projectfolder/mainMasterDofile.do" , replace

end

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

		Here are all functions for combination of
		subcommand and item type

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

cap program drop 	iefolder_newProject
	program define	iefolder_newProject

		args projectfolder newHandle

		mkdir "`projectfolder'/DataWork"

		global projectfolder "`projectfolder'/DataWork"

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

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

		*Write devisor starting globals section
		writeDevisor  `newHandle' 1 FolderGlobals

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

		*Write sub devisor starting master and monitor data section section
		writeDevisor `newHandle' 1 FolderGlobals 1 master

		*Create master data folder and add global to folder in master do file
		createFolderWriteGlobal "MasterData"  "projectfolder"  mastData  `newHandle'

		*Write sub devisor starting master and monitor data section section
		writeDevisor `newHandle' 1 FolderGlobals 2 rounds

		*Write sub devisor starting master and monitor data section section
		writeDevisor `newHandle' 1 FolderGlobals 3 monitor

		*Write sub devisor starting master and monitor data section section
		writeDevisor `newHandle' 1 End_FolderGlobals

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

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

end

cap program drop 	iefolder_newRound
	program define	iefolder_newRound

	args subHandle rndName rndAbb

	*Old file reference
	tempname 	oldHandle
	local 		oldTextFile 	"$projectfolder/mainMasterDofile.do"

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

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

	while r(eof)==0 {

		di `"`line'"'

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

		parseReadLine `"`line'"'

		if `r(ief_line)' == 0 {

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

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

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

			return list

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

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

					*Increment the section number for the new section
					local ++sectionNum

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

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

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

				}
				else {

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

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

				}

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

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

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

					*Increment the section number for the new section
					local ++sectionNum

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

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

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

				}

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

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

		di "new line read"
	}

	*Close the old file.
	file close `oldHandle'

end

cap program drop 	iefolder
	program define	iefolder

	syntax anything, projectfolder(string) [abb(string)]

	***Todo
	*Test that a folder called DataWork already exist (unless new project)
	*Test that old master do file exist
	*allow to specifiy other place for master do file

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

		Parse input

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

	gettoken subcommand item : anything

	gettoken itemType itemName : item

	local subcomand = trim("`subcommand'")
	local itemType 	= trim("`itemType'")
	local itemName 	= trim("`itemName'")

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

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

		Test input

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

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

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

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

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

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

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

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

	}

	di "All tests ok"

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

		Start making updates to the project folder

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

	*Create a temporary textfile
	tempname 	newHandle
	tempfile	newTextFile

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

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

		di "Subcommand: New"

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

			di "ItemType: Project"
			iefolder_newProject "`projectfolder'" `newHandle'
		}
		*Creating a new round
		else if "`itemType'" == "round" {

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

			di "ItemType: round"
			iefolder_newRound `newHandle' "`itemName'" "`abb'"
		}
		*Creating a new master data set
		else if "`itemType'" == "master" {

			di "ItemType: master"
			iefolder_newMaster
		}
		*Creating a new monitor
		else if "`itemType'" == "monitor" {

			di "ItemType: monitor"
			iefolder_newMonitor
		}
	}

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

	*Copy the new master dofile from the tempfile to the original position
	copy "`newTextFile'"  "$projectfolder/mainMasterDofile.do" , replace

end

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

		Here are all functions for combination of
		subcommand and item type

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

cap program drop 	iefolder_newProject
	program define	iefolder_newProject

		args projectfolder newHandle

		mkdir "`projectfolder'/DataWork"

		global projectfolder "`projectfolder'/DataWork"

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

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

		*Write devisor starting globals section
		writeDevisor  `newHandle' 1 FolderGlobals

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

		*Write sub devisor starting master and monitor data section section
		writeDevisor `newHandle' 1 FolderGlobals 1 master

		*Create master data folder and add global to folder in master do file
		createFolderWriteGlobal "MasterData"  "projectfolder"  mastData  `newHandle'

		*Write sub devisor starting master and monitor data section section
		writeDevisor `newHandle' 1 FolderGlobals 2 rounds

		*Write sub devisor starting master and monitor data section section
		writeDevisor `newHandle' 1 FolderGlobals 3 monitor

		*Write sub devisor starting master and monitor data section section
		writeDevisor `newHandle' 1 End_FolderGlobals

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

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

end

cap program drop 	iefolder_newRound
	program define	iefolder_newRound

	args subHandle rndName rndAbb

	*Old file reference
	tempname 	oldHandle
	local 		oldTextFile 	"$projectfolder/mainMasterDofile.do"

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

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

	while r(eof)==0 {

		di `"`line'"'

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

		parseReadLine `"`line'"'

		if `r(ief_line)' == 0 {

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

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

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

			return list

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

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

					*Increment the section number for the new section
					local ++sectionNum

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

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

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

				}
				else {

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

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

				}

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

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

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

					*Increment the section number for the new section
					local ++sectionNum

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

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

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

				}

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

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

		di "new line read"
	}

	*Close the old file.
	file close `oldHandle'

end


Christmas tree

Christmas tree

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/dreameater89/d3_testing.git/'


Oversight

Oversight

redo-ifchange ../src/sdtest/sdtest.rom
cp ../src/sdtest/sdtest.rom $3

error: pathspec '3/roms/sdtest.do' did not match any file(s) known to git


remove files keeping from test

remove files keeping from test

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


toplevel all.do: 'redo t' no longer works.

It's too bad, but it's actually more readable to force people to say
'redo t/all' if they really mean it.  So just fix the help message.

echo "Nothing to do.  Try 'redo t/all' or 'redo test'" >&2

echo "Nothing to do.  Try 'redo t' or 'redo test'" >&2


added images vs. text for sample B

added images vs. text for sample B

program reg_dd_compare_sampleb

local var1 `1'
local var2 `2'

local var1 img
local var2 text

local x1 1.treat#1.post

est clear
use ${stash}master, clear

// Loop over, once each for images and text
foreach x in `var1' `var2' {
 eststo: qui reg `x' `x1' i.${fe}, cluster(playerid)
 qui estadd local fixed "No"
 qui estadd local yearfe "Yes"

 eststo: qui xtreg `x' `x1' i.${fe}, cluster(playerid) fe
 qui estadd local fixed "Yes"
 qui estadd local yearfe "Yes"

 eststo: qui xtreg ln`x' `x1' i.${fe}, cluster(playerid) fe
 qui estadd local fixed "Yes"
 qui estadd local yearfe "Yes"
}

// write Latex table

esttab using "${tables}reg_dd_compare_sampleb.tex", keep(`x1') se ar2 nonotes star(+ 0.15 * 0.10 ** 0.05 *** 0.01) coeflabels(`x1' "\emph{out-of-copy X post}") order(`x1') replace booktabs s(fixed yearfe r2_a N, label("Player-Page FE" "Year FE" "adj. \$R^2\$" N )) width(\hsize) staraux mgroups("Images" "Text", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) mtitles("OLS" "OLS" "Log-OLS" "OLS" "OLS" "Log-OLS") nonum

end

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


Fix Documentation/md-to-man

Fix Documentation/md-to-man


Changing name

Changing name

*! vers 0.14.3 18mar2014
*! author: George G. Vega Yon

/**oxygen
 * @brief Sets the path where stata exe is installed.
 * @param statadir If the user wants to set it manually
 * @param force Avoids path checking.
 * @returns A global PLL_STATA_PATH.
 */

mata:
real scalar parallel_setstatapath(string scalar statadir, | real scalar force) {

	string scalar bit, flv

	// Is it 64bits?
	if (c("osdtl") != "" | c("bit") == 64) bit = "-64"
	else bit = ""

	// Building fullpath name
	if (statadir == J(1,1,"") | statadir == "") {
		if (c("os") == "Windows") { // WINDOWS
			if (c("MP")) flv = "MP"
			else if (c("SE")) flv = "SE"
			else if (c("flavor") == "Small") flv = "SM"
			else if (c("flavor") == "IC") flv = ""

			/* If the version is less than eleven */
			if (c("stata_version") < 11) statadir = c("sysdir_stata")+"w"+flv+"Stata.exe"
			else statadir = c("sysdir_stata")+"Stata"+flv+bit+".exe"

		}
		else if (regexm(c("os"), "^MacOS.*")) { // MACOS

			if (c("stata_version") < 11 & (c("osdtl") != "" | c("bit") == 64)) bit = "64"
			else bit = ""

			if (c("MP")) flv = "Stata"+bit+"MP"
			else if (c("SE")) flv = "Stata"+bit+"SE"
			else if (c("flavor") == "Small") flv = "smStata"
			else if (c("flavor") == "IC") flv = "Stata"+bit

			statadir = c("sysdir_stata")+flv+".app/Contents/MacOS/"+flv
		}
		else { // UNIX
			if (c("MP")) flv = "stata-mp"
			else if (c("SE")) flv = "stata-se"
			else if (c("flavor") == "Small") flv = "stata-sm"
			else if (c("flavor") == "IC") flv = "stata"

			statadir = c("sysdir_stata")+flv
		}
	}

	// Setting PLL_STATA_PATH
	if (force == J(1,1,.) | force == 1)	{
		if (!fileexists(statadir)) return(601)
	}

	if (!regexm(statadir, `"^["]"')) st_global("PLL_STATA_PATH", `"""'+statadir+`"""')
	else st_global("PLL_STATA_PATH", statadir)

	display(sprintf("{text:Stata dir:} {result: %s}" ,statadir))
	return(0)
}
end

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


changeset stata file work begun

changeset stata file work begun

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


gen id stata example

gen id stata example

error: pathspec 'Topics/Stata' did not match any file(s) known to git
error: pathspec 'Examples/Generate' did not match any file(s) known to git
error: pathspec 'IDs/generate_ids_example.do' did not match any file(s) known to git


arudata

arudata

*! Stata-Syntax for outdat.ado 1.2
* Change-log
* ----------
* Version 0.1: First draft
version 7.0
program define arudata
syntax anything
cd "/Users/iMac6/Desktop/_ARU2018/8_arudata/eh"
quietly {
clear *
import delimited using `anything'.csv, delimiter(";")
do `anything'.do
}

end
exit

Alvaro Chirino
University of San Andres
faculty of mathematics and natural sciences
+591 70694453

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