text
stringlengths
0
538k
*! 1.2.1 NJC 1 March 2012 *! 1.2.0 NJC 15 September 2008 * 1.1.1 GML NJC 26 February 2002 * 1.1.0 GML NJC 25 February 2002 * 1.0.0 21 November 2001 program distinct, rclass sortpreserve byable(recall) version 8.0 syntax [varlist] [if] [in] [, MISSing Abbrev(int -1) Joint /// MINimum(int 0) MAXimum(int -1) ]...
** Downloaded from http://blogs.worldbank.org/impactevaluations/tools-of-the-trade-doing-stratified-randomization-with-uneven-numbers-in-some-strata * Example code by Mirian Bruhm and David McKenzie # delimit ; *clear all; //EDIT: moved to calling routine *cap log close; *set mem 200m; *use BlogStrataExample.dta, cle...
sysdir set PERSONAL "../../" global S_ADO "PERSONAL;BASE;." clear_all, closealllogs log using "test.log", replace name(test) version 13 local init_seed 467 //from exampleofstratifying set seed `init_seed' local ngroups 6 local strat_vars = "variableA variableB variableC variableD" local ttypes = "obalance reduction f...
*Notes: * If you want the trace log from the optimizer from synth run it in batch mode and on Windwos it * creates a 'temp' file. *Todo: *On linux, -synth, nested- it eats up all the memory. This didn't seem to be reported by -memory-. cap log close _all log using "test.internal.log", replace name(test) clear all sy...
*! version 1.0 Brian Quistorff <bquistorff@gmail.com> *! usepackage_simple.ado -- Stata module to download and install user packages necessary to run a do-file *! include the net(loc) option if you want to install the package from non-SSC sources (the default) *! A simplified version...
*! version 1.2 Brian Quistorff <bquistorff@gmail.com> *! Auto wraps a long line to broken up ones (that graph commands turn into different lines) *! Wrapped has the "" quotes to separate lines *! Usage: *! wrap_text , unwrappedtext(`longtext') wrapped_out_loc(wrapped) *! twoway ..., note(`wrapped') * With simple testi...
*! version 0.3 bquistorff@gmail.com *! Writes out a string to a file *! LaTeX automatically adds an extra space after \input (cf http://tex.stackexchange.com/questions/18017/) *! Use rm_final_space_tex if you don't want this *! (e.g. you're inserting numbers and a symbol should immediately follow) program writeout_txt...
*=============================================================================== * PROGRAM: regressby.ado * PURPOSE: Performs fast grouped univariate OLS regressions. * The following commands are equivalent: * regressby y x, by(byvars) * statsby, by(byvars) clear: reg y x * Except regressby will run...
cd C:\Users\Mike\Documents\Github\stata-modern cap mkdir figs *------------------------------------------------------------------------------- * Fig 1: Histograms *------------------------------------------------------------------------------- sysuse nlsw88, clear set scheme s2color histogram wage, title("Histogram...
capture program drop knit program define knit args in _knit_with_code_tags "`in'" _make_code_blocks "`in'" end capture program drop _knit_with_code_tags program define _knit_with_code_tags args in set more off file open f using "`in'", read local out = subinstr("`in'", ".domd", ".md1", 1) log using...
This is the generate folder in [Fan](https://fanwangecon.github.io/)'s [Stata4Econ](https://fanwangecon.github.io/Stata4Econ/) repository. Materials gathered from various [projects](https://fanwangecon.github.io/research) in which STATA code is used. Please contact [FanWangEcon](https://fanwangecon.github.io/) for issu...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/REconTools - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/Tex4Econ - http://...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/REconTools - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/Tex4Econ - http://...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/CodeDynaAsset/ - http://fanwangecon.github.io/Ma...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/CodeDynaAsset/ - http://fanwangecon.github.io/Ma...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/REconTools - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/Tex4Econ - http://...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/REconTools - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/Tex4Econ - http://...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/CodeDynaAsset/ - http://fanwangecon.github.io/Ma...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/REconTools - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/Tex4Econ - http://...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/CodeDynaAsset/ - http://fanwangecon.github.io/Ma...
linear regression in Stata
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/CodeDynaAsset/ - http://fanwangecon.github.io/Ma...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/CodeDynaAsset/ - http://fanwangecon.github.io/Ma...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/REconTools - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/Tex4Ec...
// do "C:\Users\fan\Stata4Econ\reglin\multipanel\allpurpose\allpurpose_prog.do" // content file of allpurpose.do ///////////////////////////////////////////////// ///--- C. Define Regression Strings ///////////////////////////////////////////////// foreach it_pan_ctr of numlist 1(1)$it_pan_cnt { foreach it_col_ctr...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/CodeDynaAsset/ - http://fanwangecon.github.io/Ma...
Multi-Panel Regressions
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/CodeDynaAsset/ - http://fanwangecon.github.io/Ma...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/CodeDynaAsset/ - http://fanwangecon.github.io/Ma...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/CodeDynaAsset/ - http://fanwangecon.github.io/Ma...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/CodeDynaAsset/ - http://fanwangecon.github.io/Ma...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/CodeDynaAsset/ - http://fanwangecon.github.io/Ma...
cls clear macro drop _all /* Back to Fan's Stata4Econ or other repositories: - http://fanwangecon.github.io - http://fanwangecon.github.io/Stata4Econ - http://fanwangecon.github.io/R4Econ - http://fanwangecon.github.io/M4Econ - http://fanwangecon.github.io/CodeDynaAsset/ - http://fanwangecon.github.io/Ma...
/* statapush: Stata module for sending push notifications Authors: William L. Schpero and Vikram Jambulapati Contact: william.schpero@yale.edu Date: 060516 Version: 3.0 */ capture program drop statapush program define statapush version 12.1 syntax [using/], Message(string) [Token(string) Userid(string)] [Attac...
/* statapushpref: Stata module to save preferences for statapush Authors: William L. Schpero and Vikram Jambulapati Contact: william.schpero@yale.edu Date: 022016 Version: 1.0 */ capture program drop statapushpref program define statapushpref version 12.1 syntax, Token(string) Userid(string) Provider(string) ...
tempname fout file open `fout' using "mystanmodel.stan", write replace #delimit ; foreach line in "data {" " int N;" " real x[N];" "}" "parameters{" " real mu;" "}" {; #delimit cr file write `fout' "`line'" _n } file close `fout' //stan ...
capture program drop inline program define inline syntax , MODELfile(string) [THISfile(string)] // what if modelfile already exists? should there be a replace suboption? tempname fin local tdir=c(tmpdir) // fetch temp do-file copy if no thisfile has been named if "`thisfile'"=="" { tempname lsin if "$S_OS"=="windows...
capture program drop rdump program define rdump version 11.0 syntax [, Rfile(string) Matrices(string) Globals(string) REPlace] // set default file name if "`rfile'"=="" { local rfile="R_in.R" } // check whether rfile exists already capture confirm file "`rfile'" if !_rc & "`replace'"=="" { display as error "`rfile...
// Bernoulli example: // replace with your cmdstan folder's path global cmdstandir "/root/cmdstan/cmdstan-2.6.2" // here we present four different ways of combining the Stan model with your do-file //############################################## // Version 1: write a separate model file /* For this example, we ca...
capture program drop stan program define stan version 11.0 syntax varlist [if] [in] [, DATAfile(string) MODELfile(string) /// INLINE THISFILE(string) RERUN /// INITsfile(string) LOAD DIAGnose OUTPUTfile(string) MODESFILE(string) /// CHAINFile(string) WINLOGfile(string) SEED(integer -1) CHAINS(integer 1) /// WARMUP...
capture program drop windowsmonitor program define windowsmonitor version 11.0 syntax ,COMMAND(string asis) [ WINLOGfile(string asis) waitsecs(integer 10) ] // stop if operating system is not Windows if lower("$S_OS")!="windows" { dis as error "windowsmonitor can only run under a Windows operating system" error 60...
version 14.0 capture program drop stan_schools program define stan_schools syntax varlist [if] [in] [, MODELfile(string asis) /// Clusterid(varname) /// RSlopes(varlist) /// GLOBALS(string asis) /// BETAPriors(string asis) /// HETvar(varname) /// THETAPrior(string asis) ...
cd "C:\Users\RLGrant\Dropbox\Software\StataStan\stan_examples" use "schools.dta", clear qui tab school global M=r(r) qui count global N=r(N) stan_schools Y VR1 VR2 Gender LRT, rslopes(denom2 denom3 sgender) /// globals("N M") clusterid(school) /// stanopts(cmd("C:/Users/RLGrant/cmdstan-2.6.2"))
// uncomment if Stata-SVM is not installed to the system adopath ++ "../../src" use classification_bug // training which does the wrong thing svm category q*, prob // tuning parameters pulled out of a hat from https://github.com/scikit-learn/scikit-learn/issues/4800 // which causes //svm category q*, prob c(10) gam...
* experimenting with building subcommands * I want to the equivalent of python's "def wrap(a, *rest): if a == 1: one(*rest)", where the arguments are * Unfortunately, the Stata quoting rules are more arcane than even bash's * references: poor amounts of googling, Nick Cox, and cluster.ado and duplicates.ado in the base...
sub x , o(7) sub x using haphazard lolcats, in the everworld(8) of time(-1) sub y , eighty
// usage: stata do stata_wrap.do $SCRIPT $LOG $RC // // Wraps $SCRIPT so that its output goes to $LOG and error code to $RC, // and it ensures Stata comes down at the end even if there was an error. // - it's an imperfect wrapper: $LOG ends up with header and footer cruft from 'log' set linesize 119 * make all platfo...
/* export_svmlight: export the Stata dataset to a .svmlight format file. See _svmlight.c */ program _svmlight, plugin /*load the C extension if not already loaded*/ program define export_svmlight version 13 syntax varlist(numeric) [if] [in] using/ quietly { capture plugin call _svmlight `varlist' `if' `i...
/* import_svmlight: import an .svmlight format file, replacing the current Stata dataset. See _svmlight.c */ * The variables created will be 'y' and 'x%d' for %d=[1 through max(feature_id)]. * Feature IDs are always positive integers, in svmlight format, according to its source code. * TODO: rename to svm_use and fig...
/* svmachines: the entry point to the support vector fitting algorithm */ program define svmachines *! version 1.1.0 version 13 //plugin call does not handle factor variables. // xi can pre-expand factors into indicator columns and then evaluate some code. // However xi interacts badly with "plugin call"; j...
/* svmacines_example: download and run the requested sample code from the svmachines package */ /* */ /* To use this with a different package, just replace every "svmachines". */ program define svmachines_examp...
/* svm_ensurelib: at runtime, make sure libsvm is available and loadable */ /* This would be ensurelib.ado, but for packaging safety, because Stata has no sensible way of protecting against namespace conflicts, this gets the same prefix as the rest of the package. If you want to use ensureli...
/* svm_predict: after fitting an SVM model with svm, construct predicted classes/values (depending on the type of the active SVM) */ /* load the C extension */ svm_ensurelib // check for libsvm program _svmachines, plugin // load the wrapper for libsvm program define svm_predict, eclass version 13 s...
/* model2stata: a subroutine to convert the global struct svm_model that lives in the DLL to a mixture of e() entries, variables, and matrices. * * Besides being usefully modular, this *must* be its own subroutine because it needs to be marked eclass. * This is because, due to limitations in the Stata C API, there h...
/* _svm_train: this is the meat of the Stata interface to the fitting algorithm. This is called by svm_train; though Stata programs can call subprograms defined in the same file as them, similar to Matlab, this has to be a separate file as the special command 'xi' used there apparently cannot */ /* load the C e...
// Setup sysuse auto // Machine learning methods like SVM are very easy to overfit. // To compensate, it is important to split data into training and testing sets, fit on // the former and measure performance on the latter, so that performance measurements // are not artificially inflated by data they've already seen....
// Setup use attitude_indicators // Shuffle set seed 12998 gen u = uniform() sort u // Train/test split local split = floor(_N*3/4) local train = "1/`=`split'-1'" local test = "`split'/`=_N'" // Model svmachines attitude q* in `train', kernel(poly) gamma(0.5) coef0(7) prob predict P in `test', prob // the value in ...
// Setup use attitude_indicators // Shuffle set seed 4532 gen u = uniform() sort u // Train/test split local split = floor(_N*3/4) local train = "1/`=`split'-1'" local test = "`split'/`=_N'" // In general, you need to do grid-search to find good tuning parameters. // These values of kernel, gamma, and coef0 just hap...
// Setup webuse highschool // Shuffle set seed 793742 gen u = uniform() sort u // Train/test split local split = floor(_N/2) local train = "1/`=`split'-1'" local test = "`split'/`=_N'" // Regression is invoked with type(svr) or type(nu_svr). // Notice that you can expand factors (categorical predictors) into sets of...
/* export_svmlight: export the Stata dataset to a .svmlight format file. See _svmlight.c */ program _svmlight, plugin /*load the C extension if not already loaded*/ program define export_svmlight version 13 syntax varlist(numeric) [if] [in] using/ quietly { capture plugin call _svmlight `varlist' `if' `i...
/* import_svmlight: import an .svmlight format file, replacing the current Stata dataset. See _svmlight.c */ * The variables created will be 'y' and 'x%d' for %d=[1 through max(feature_id)]. * Feature IDs are always positive integers, in svmlight format, according to its source code. * TODO: rename to svm_use and fig...
/* svmachines: the entry point to the support vector fitting algorithm */ program define svmachines *! version 1.1.0 version 13 //plugin call does not handle factor variables. // xi can pre-expand factors into indicator columns and then evaluate some code. // However xi interacts badly with "plugin call"; j...
/* svmacines_example: download and run the requested sample code from the svmachines package */ /* */ /* To use this with a different package, just replace every "svmachines". */ program define svmachines_examp...
/* svm_ensurelib: at runtime, make sure libsvm is available and loadable */ /* This would be ensurelib.ado, but for packaging safety, because Stata has no sensible way of protecting against namespace conflicts, this gets the same prefix as the rest of the package. If you want to use ensureli...
/* svm_predict: after fitting an SVM model with svm, construct predicted classes/values (depending on the type of the active SVM) */ /* load the C extension */ svm_ensurelib // check for libsvm program _svmachines, plugin // load the wrapper for libsvm program define svm_predict, eclass version 13 s...
/* model2stata: a subroutine to convert the global struct svm_model that lives in the DLL to a mixture of e() entries, variables, and matrices. * * Besides being usefully modular, this *must* be its own subroutine because it needs to be marked eclass. * This is because, due to limitations in the Stata C API, there h...
/* _svm_train: this is the meat of the Stata interface to the fitting algorithm. This is called by svm_train; though Stata programs can call subprograms defined in the same file as them, similar to Matlab, this has to be a separate file as the special command 'xi' used there apparently cannot */ /* load the C e...
// Setup sysuse auto // Machine learning methods like SVM are very easy to overfit. // To compensate, it is important to split data into training and testing sets, fit on // the former and measure performance on the latter, so that performance measurements // are not artificially inflated by data they've already seen....
// Setup use attitude_indicators // Shuffle set seed 12998 gen u = uniform() sort u // Train/test split local split = floor(_N*3/4) local train = "1/`=`split'-1'" local test = "`split'/`=_N'" // Model svmachines attitude q* in `train', kernel(poly) gamma(0.5) coef0(7) prob predict P in `test', prob // the value in ...
// Setup use attitude_indicators // Shuffle set seed 4532 gen u = uniform() sort u // Train/test split local split = floor(_N*3/4) local train = "1/`=`split'-1'" local test = "`split'/`=_N'" // In general, you need to do grid-search to find good tuning parameters. // These values of kernel, gamma, and coef0 just hap...
// Setup webuse highschool // Shuffle set seed 793742 gen u = uniform() sort u // Train/test split local split = floor(_N/2) local train = "1/`=`split'-1'" local test = "`split'/`=_N'" // Regression is invoked with type(svr) or type(nu_svr). // Notice that you can expand factors (categorical predictors) into sets of...
program define clockseed set seed `= mod(clock("$S_DATE $S_TIME","D M 20Y hms"),2^31)' end
/* clone.ado: generate a perfect copy of a variable: type, labels, etc. syntax: clone newvar oldvar [if] [in] You can use 'if' and 'in' to control what values; values that don't match will be set to missing. If you want to clone a variable's metadata but not values use the idiom ". clone new old if 0". NB: Th...
/* 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 d...
/* ensurepkg: automagically install needed packages. * * syntax: * ensureado cmd, [pkg(package_name) from(url)] * * cmd: to detect if the package is installed, look for either of "`cmd" and "`cmd'.ado" in the adopath. * pkg: specify pkg explicitly if the command and package do not have the same name. * from: i...
// grid search for good SVM parameters // by Matthias Schonlau // enhanced to use cv.ado by Nick Guenther // // this is not a function because // - it is technically difficult: // - looping over ranges of arbitrary parameters is muddy (the sklearn GridSearch object has to take a dictionary of parameter->[set of valu...
/* mlogit_predict: extract classifications from an mlogit model * mlogit only gives probabilities. actually translating this to classes is hard. * */ program define mlogit_predict if("`e(cmd)'"!="mlogit") { di as error "mlogit_predict must only be run after mlogit" exit 1 } gettoken target 0 : 0 ...
// Setup pause on sysuse nlsw88, clear // This dataset has labour data: employment conditions crossed with demographic information. // (for clarity, we cut the small amount of respondents which answered "other" // and the few rows with missing data that svmachines cannot tolerate) // (in a real analysis you should ha...
clockseed sysuse auto svm foreign headroom gear_ratio weight, type(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(`=floor(_N/5)') shuffle est(type(svc) gamma(0.4) c(51)) gen err = foreign != P qui su...
// ethyl acrylate data , Bates and Watts, A1.10 clear import excel using "tests/ethyl.xlsx", firstrow gen viscosity = exp(ln_viscosity) set seed 100 gen u=uniform() sort u ///////////////////////////////////////////////////////////////////// local trainn=30 gen train= 0 replace train=1 if _n<=`trainn' graph matri...
* export_svmlight.do sysuse auto capture rm "tests/auto.svmlight" // notice: auto contains a string variable and its class variable is last // we explicitly rearrange them during the export stating the order of variables (Stata handles the indirection, hiding it from the plugin) export_svmlight foreign price-gear_ratio...
program _svm_getenv, plugin plugin call _svm_getenv, PATH di "_getenv=`_getenv'"
* loadplugin.do * unconditionally unload the plugin * this is only relevant if this do file is reused in the same session capture program drop _svmachines * load it! program _svmachines, plugin
* export.do sysuse auto svmachines foreign price-gear_ratio if !missing(rep78) in 41/60 /*train on some of the data; this range is chosen to cover 10 each of each kind of car*/ predict P in 50/70 /* test, on both part of the training and part of the testing data */ * fill in the rest and observe the error rate * Sta...
* train.do sysuse auto drop make order gear_ratio // gear_ratio is a floating point value, but it only lives between 2 and 4 in this dataset, so libsvm casts it to classes 2 and 3 svmachines * if !missing(rep78) do tests/helpers/inspect_model.do predict Q list `e(depvar)' Q
* train.do sysuse auto drop make order headroom // headroom is a floating point variable but comes in .5-increment levels svmachines * if !missing(rep78), sv(SV) list SV do tests/helpers/inspect_model.do predict Q list `e(depvar)' Q
* predict_oneclass.do sysuse auto replace foreign = 3 if _n < 10 replace foreign = 4 if _n > 10 & _n < 20 svmachines price-gear_ratio if !missing(rep78), sv(SV) type(one_class) predict P list P*
* predict_oneclass_scores.do sysuse auto replace foreign = 3 if _n < 10 replace foreign = 4 if _n > 10 & _n < 20 svmachines price-gear_ratio if !missing(rep78), sv(SV) type(one_class) predict P, scores list P*
* export.do sysuse auto svmachines foreign price-gear_ratio if !missing(rep78), prob capture noisily predict P, prob capture noisily predict P2 list foreign P*
* predict_probability_strangelabels * Ensure that the complicated labelling code buried in predict, prob behaves itself even when labels are shifted * The final list should show that the probability columns are labelled with strings which mostly match what the actual values were. sysuse auto replace foreign = foreign+...
* predict_scores.do sysuse auto svmachines foreign price-gear_ratio if !missing(rep78) capture noisily predict P, scores list foreign P*
* predict_scores_and_probability.do sysuse auto svmachines foreign price-gear_ratio if !missing(rep78), prob predict P1, prob predict P2, scores capture noisily predict P3, prob scores if(_rc == 0) { di as err "prob and scores should be mutually exclusive options" exit 1 } list foreign P*
* predict_scores_multiclass * like predict_scores, but this exercises the complicated triangular label matrix code by making sure there's more than one pair sysuse auto label define origin 2 "Dodge", add label define origin 3 "Buick", add replace foreign = 2 in 20/22 replace foreign = 3 in 4/10 svmachines foreign pri...
* predict_svr.do quietly do tests/train_svr.do predict P in 50/70 predict P2 generate error = abs(price - P2) //notice: subtraction, not comparison, because we're regressing, not classifying list price P P2 error summarize error
* predict_svr_scores.do quietly do tests/train_svr.do predict P in 50/70 /* test, on both part of the training and part of the testing data */ predict P2, scores list price P*
* preimport_svmlight.do program _svmlight, plugin plugin call _svmlight, "import" "pre" "tests/duke.svmlight" scalar list
local mQQ : env QQ di "First: mQQ=`mQQ'" // the \$ quotes the $, because otherwise Stata, apparently, tries to interpret it !echo And the shell says: \$QQ program _svm_setenv, plugin plugin call _svm_setenv, QQ "hello me hearties" local mQQ : env QQ di "After: mQQ=`mQQ'" !echo And the shell says: \$QQ
* train.do sysuse auto svmachines foreign price-gear_ratio if !missing(rep78) do tests/helpers/inspect_model.do
* train.do sysuse auto svmachines foreign price-gear_ratio if !missing(rep78), sv(SV) list SV do tests/helpers/inspect_model.do