Permalink
Browse files

require.ado and more doc

  • Loading branch information...
1 parent 231bdc8 commit 8bcd2e4e80d7bca45d6420ca63ed475a1d03e842 @briatte committed Oct 9, 2012
View
@@ -1,13 +1,27 @@
# SRQM: Programs
-This folder contains the `srqm` utilities to set up a computer for this course, as explained in the [README](https://github.com/briatte/srqm/blob/master/README.md) file of the `SRQM` folder.
+The folder contains some teaching utilities:
-The commands rely on the architecture of the `SRQM` folder, a.k.a the 'Teaching Pack', which contains the course material. All commands should be run with this folder set as the working directory.
+- the `packages_required` command to check for the existence of commands installed through additional packages
+- the `srqm` utilities to set up a computer for our course, as explained in the [README](https://github.com/briatte/srqm/blob/master/README.md) file of the `SRQM` folder
+- the `tsst` command to export summary statistics tables as tab-separated values
-The folder also contains the `tsst` command to export summary statistics tables as tab-separated values, in order to assist students in completing one of the first steps of their research project.
+All commands were written to assist [students](http://f.briatte.org/teaching/quanti/) in completing their research projects.
+
+## `packages_required`
+
+Checks whether a given list of commands are currently installed in Stata, and [if not][statalist-tip], tries to install the corresponding package at the [SSC archive](http://ideas.repec.org/s/boc/bocode.html).
+
+### Syntax
+
+ packages_required fre spineplot tabout etc
+
+The command is used in course do-files to send a legible one-line warning about package dependencies without slowing down execution with multiple `ssc install` commands.
## `srqm`
+The `srqm` utilities rely on the architecture of the `SRQM` folder, a.k.a the '[Teaching Pack](http://f.briatte.org/srqm/)', which contains the course material. All `srqm` commands should be run with this folder set as the working directory.
+
The `srqm` utilities require one command and optionally one subcommand to execute:
srqm command [subcommand] [, nolog]
@@ -51,7 +65,7 @@ If the `SRQM` folder has been renamed to `SRQM-USB`, the subcommand ignores the
Installs the additional Stata packages and [graph schemes by Edwin Leuven](http://leuven.economists.nl/stata.php) used in the course do-files. Requires Internet access to execute properly. Usually runs in less than five minutes.
-The subcommand will try to run as quickly as possible by skipping packages that are [already installed](http://www.stata.com/statalist/archive/2009-12/msg00493.html). This behaviour can be overriden by passing the `forced` option.
+The subcommand will try to run as quickly as possible by skipping packages that are [already installed][statalist-tip]. This behaviour can be overriden by passing the `forced` option.
### `srqm check`
@@ -109,3 +123,5 @@ Far more sophisticated output options appear in packages like `estout` or `tabou
- Type `tsst using example` for a working example.
Students are referred to the documentation of their text or spreadsheet editor to learn how to import a tab-separated values document, or how to convert tab-delimited text into tabular output.
+
+[statalist-tip]: http://www.stata.com/statalist/archive/2009-12/msg00461.html
View
Binary file not shown.
View
@@ -0,0 +1,14 @@
+cap pr drop require
+program require
+ syntax anything
+ tokenize `anything'
+
+ while "`*'" != "" {
+ cap which `1'
+ if _rc==0 di as txt "Package " as inp "`1'" as txt " is installed."
+ if _rc==111 cap qui ssc install `1', replace
+ if _rc==631 di as err "Could not connect to the SSC archive to look for package " as inp "`1'"
+ if _rc==601 di as err "Could not find package " as inp "`1'" as err " at the SSC archive"
+ macro shift
+ }
+end
View
@@ -23,7 +23,7 @@ program srqm
local install = "catplot ciplot estout fre kountry leanout log2do2 lookfor_all mkcorr revrs spineplot tab_chi tabout"
// interrupt logs
- cap log close _all
+ if `log' cap log close _all
// check syntax
if `setup' | `check' | `clean' {
@@ -303,14 +303,17 @@ program srqm
//
di as inp _n "Cleaning work files..." // probably requires X Window System
- local expr = "Programs/*[^clean].log"
+ local expr = "Programs/*.log"
cap !rm `expr'
local expr = "Replication/*[^backup].log"
cap !rm `expr'
local expr = "Replication/*-files"
cap !rm -R `expr'
+
+ local expr = "Replication/BriattePetev"
+ cap !rm -R `expr'
}
}
@@ -0,0 +1,9 @@
+# SRQM: Replication files
+
+The replication code for this course is provided as Stata do-files. There is one do-file per session, plus three draft examples for assignments. Each do-file follows more or less the same code structure.
+
+The datasets used in the do-files are stored in the `Datasets` folder and are documented in its [README](https://github.com/briatte/srqm/blob/master/Datasets/README.md) file. For the do-files to execute properly, the working directory must be set to the `SRQM` folder.
+
+Several additional packages are required at various points in the do-files. If you are online when replicating the do-files, a short loop at the beginning of the code will install any missing element.
+
+(Complete documentation forthcoming.)
View
Binary file not shown.
View
@@ -10,28 +10,33 @@
* you have set up Stata for the course by setting the working directory to the
* SRQM folder. You should have run and reviewed all previous do-files first.
-* Required packages.
-foreach p in fre spineplot {
- cap which `p'
- if _rc==111 ssc install `p'
-}
* =========
* = SETUP =
* =========
-* Data.
-use "Datasets/nhis2009.dta", clear
+* Required packages.
+foreach p in fre spineplot {
+ cap which `p'
+ if _rc==111 ssc install `p'
+}
* Create a folder to export all files.
-global pwd=c(pwd)
-global wd "Replication/draft1-files" // !note: edit to fill in your own names
+global wd "Replication/BriattePetev" // !note: edit to fill in your own names
cap mkdir "$wd"
-cd "$wd"
* Log.
-cap log using "draft1.log", name(draft1) replace
+cap log using "$wd/draft1.log", name(draft1) replace
+
+
+* ========
+* = DATA =
+* ========
+
+
+* Data.
+use "Datasets/nhis2009.dta", clear
* Subsetting to data from most recent year.
drop if year!=2009
@@ -40,6 +45,9 @@ drop if year!=2009
keep serial psu strata perweight age sex raceb educrec1 ///
health height weight uninsured vig10fwk yrsinus
+* Patterns of missing data.
+misstable pat *
+
* Set NHIS individual weights (used only for illustrative purposes).
svyset psu [pw=perweight], strata(strata) vce(linearized) singleunit(missing)
@@ -258,7 +266,7 @@ spineplot hins race, scale(.7) name(hins, replace)
* of both commands in use.
* Export with tsst command.
-tsst using draft1-stats.txt, su(bmi age) fr(female edu3 health phy race hins) replace
+tsst using draft1-files/stats.txt, su(bmi age) fr(female edu3 health phy race hins) replace
* =======
@@ -269,9 +277,6 @@ tsst using draft1-stats.txt, su(bmi age) fr(female edu3 health phy race hins) re
* Close log (if opened).
cap log close draft1
-* Reset working directory.
-cd "$pwd"
-
* ==========
* = BONUS! =
Oops, something went wrong.

0 comments on commit 8bcd2e4

Please sign in to comment.