/software

Here's some software I've written:  

NOTES

ADO-FILES ARE BEING MIGRATED TO CODE.GOOGLE.COM or SSC (if appropriate) & I'LL INCLUDE A DESCRIPTION AND LINK HERE WHEN THEY ARE UPLOADED.  EMAIL ME ABOUT OBTAINING ANY SOFTWARE LISTED BUT WITHOUT ACTIVE LINKS

Stata

Quicklinks:

My ado-files submitted to SSC Archives at IDEAS 

My ado-files for Stata at the Google repository

My Statalist Postings 

My Stata Users Forum Posts


Below are some Stata .ado files I've written (full archive here: http://code.google.com/p/eab-adofiles/downloads/list )

statplot.ado

(co-authored with Nick J. Cox)

-statplot-  plots the summary statistics of a varlist as groups labeled on the axis. In contrast, -graph bar- plots the summary statistics of a varlist as multiple plots with variable labels in the legend. So, by moving the variable labels to the axis -statplot- helps avoid the need to use a legend (or saving it for plots with several over() and/or a by() groupings). Normally with graph bar, this could only be done using if the data were first manipulated (most likely collapsed and then transposed).   

The basic syntax is:

    statplot varlist [if exp] [in range] [weight]   [ , statistic(stat) over(over_options) ///

             [ over(over_options) ] missing   xpose recast(plottype)  ///

             varnames varopts(varlist_options) graph_options ]

See the -statplot- help file for more information and description of the syntax options.

Also, see this /research_notes posting and/or download this do-file for some more advanced -statplot- examples.

Here's some example code:

    . sysuse citytemp, clear

    . statplot heatdd cooldd

    . statplot heatdd cooldd, over(region)

    . statplot temp*, over(region, sort(1) descending) s(sd) blabel(bar, format(%2.1f))

    . sysuse census, clear

    . statplot marriage divorce, over(region) s(sum)

    . statplot marriage divorce, over(region) s(sum) xpose

    . statplot marriage divorce, over(region) s(sum) xpose varnames

    . sysuse nlsw88, clear

    . statplot wage, over(race) over(union)

    . separate wage, by(race) veryshortlabel

    . statplot wage?, over(union)

-statplot- is available for download from the SSC [1] [2





obsdiff.ado

This ado-file helps you find the differences between observations/records in Stata.  If you've got many variables/columns and you want to identify for which variables two or more records differ,  -obsdiff- can report these differences for specified observation ranges.

Syntax: 

    obsdiff [varlist] [if] [using/] [, Rows(numlist) ALL]

where either option [all] or [rows()] must be specified.

Options:

using - Saves report to logfile

rows() - Define the rows to compare observations across

all - Shows differences for all rows (same as specifying rows(1/`=_N')

varlist - If specified, obsdiff will only find differences rows in -rows()- for the [varlist]. 

If [varlist] is not specified, -obsdiff- will report differences for all variables in -rows()- specified.

Stored Values

Any variables with differences are stored in the scalar `r(diff_vars)'.

Examples

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

// Example 1: Find differences in specified rows//

sysuse cancer, clear

drop age

**duplicate records in 1/3 except for studytime and _t

obsdiff, rows(1/3)

**

obsdiff for rep78, r(1/20)

obsdiff rep78 if for==0, r(1/20)

obsdiff pri if for==1, r(1/70)

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

//Example 2: Find differences in all rows for specified varlist//

sysuse auto, clear

keep for

g f2 = for

replace f2 = f2+1 in 25/50

**note: you can use explicit subscripting

******  to identify the max row

obsdiff f*, r(1/`=_N')

**or using "all" option:

obsdiff, all

obsdiff for, all

**save to log file "test"**

obsdiff rep78 if for==1 using "test", all

**vars differences in scalar `r(diff_vars)'**

di "`r(diff_vars)'"

**********************!

Get -obsdiff- from SSC





nearmrg

- performs nearest match merging of two datasets on the values of the numeric variable nearvar.

nearmrg was designed as a way to use lookup tables that have binned or rounded values on the variable of

interest. 

Syntax:

   nearmrg [varlist] using , nearvar(varname) [ limit(real) genmatch(newvarname) lower upper roundup

        type(mergetype) mergeoptions]

Description:

The user specifies whether the master dataset should be matched with observations in the using dataset

with the value closest and higher (or upper) than each nearvar value, or observations nearest and lower

than near values.

Since the nearvar must be a numeric variable, be sure to convert any time-date string variables to their

numeric equivalent (see datetime). Variables may be specified in an optional varlist and these

variables are treated as rd merge variable which must match exactly. This option allows nearest matching

within subsets defined by the varlist. nearmrg requires Stata 11+ since it utilizes the newer merge

command syntax.

Notes:

The original -nearmrg- program was written in in 2003 and was co-authored by M Blasnik and K Smith; 

I rewrote much of the code in 2012 and took over as author for all versions 2.1+.  The newest version of -nearmrg-

borrows heavily from the logic in the original version of the program and owes much to the original programming

approach.  Beyond adding code to work with the new Stata 11+ merge syntax, the new program allows the user to

specify a limit for the distance to the nearest match based on the 'nearvar()' and adds options to have more fine tune 

control over the type of merge (1:1, m:1, 1:m).

Examples:

//Find car prices in "autoexpense.dta" within $50 of "auto.dta"//

**1:  create 'using' data**

webuse autoexpense.dta, clear

rename make make2

sa "using.dta", replace

**2:  merge to auto.dta by price**

sysuse auto.dta, clear

nearmrg  using "using.dta", upper nearvar(price) genmatch(usingmatch) limit(50) 

list make* price  usingmatch _m if inrange(_m, 3, 5)

Download nearmrg from SSC with the command:

ssc install nearmrg, update




mac_unab 

Stata module to unabbreviate Global Macro Lists

Description:  mac_unab unabbreviates a global macro list.  Similar to unab it finds all macros (rather than variables) that exist and match a pattern and places them in a macro list.

Keywords:  unabbreviate, unab, macro, global macro, extended functions

Requires Stata 9.2 

Syntax:

 mac_unab mname :  patternlist [ , ignore(string) ]

Required Options:

mname  - is the name of the global macro created to contain all macros that match the

        patternlist.

patternlist  - describes the global macro list that should be unabbreviated.

        patternlist should consist of a stub followed by an asterisk (e.g., gr*) which

        will match global macros starting with the stub -- so gr* would match already

        defined global macros green and grown.

        Currently, global macros can only be matched using the asterisk following the

        stub (e.g., gr*), the asterisk cannot precede or split the stub (e.g., *gr or

        gr*on).

Options: 

ignore()  - allows a space delimited list of words that you want to remove from

        consideration when finding the macros in patternlist to unabbreviate. 

Examples:

//Create some data//

    . clear

    . set obs 10

    . g x = round(runiform()*100, .05)

    . g x2 = int(runiform()*100)

    . replace x = -2.5 in 1

//Convert Numbers to Text//

    . num2words x, g(x_converted)

    . num2words x, g(x_rounded) round

    . replace x_converted = proper(x_rounded)

    . num2words x, g(x2_ordinal) ordinal

//Use Converted Text in Graph//

    . egen mx = mean(x)

    . num2words mx, round

    . gr bar x , over(x2_ordinal, sort(1)) ///

        note( X for Obs 2 is `=x_rounded[2]') ///

        text(60 20 `"Mean = `=mx2'"', box )

Get mac_unab from SSC Archives





num2words.ado

Stata module to Convert Numbers to Words.  num2words converts numbers 

(including real and ordinal numbers) in a single numvar to

text.  It is useful for converting numbers to text for insertion in graph or table

titles, captions, or labels; value or variable labels; charactersics or notes; or,

this utility can convert numbers to words for inclusion in the text of a document

created from Stata via commands like file write, texdoc(if installed), or rtfutil(if

installed).

Syntax: 

    num2words numvar [if exp] [in range] [ , generate(newvar) round ordinal ]

Notes:

num2words converts:

     1. positive or negative numbers, including fractional numbers;

     2. numbers up to 999 trillion (15 places to the left of the decimal);

     3. fractional numbers up to the millionths place (6 places to the right of the

  decimal);

Converted text will be automatically truncated if the conversion is longer than

Stata's character limit for string variables (See help limits and help data_types for

more).

Options:

generate() - specifies the new string variable containing the converted text for numvar.

        If no variable name is specified the default is numvar2.

round - tells num2words to ignore fractional part during conversion to text.

ordinal - adds the appropriate suffix to the cardinal number (fractional part ignored)

        to form ordinal number (421 converted to 421st or 2 converted to 2nd).

if and in are allowed.

Examples:

/

/Create some data//

    . clear

    . set obs 10

    . g x = round(runiform()*100, .05)

    . g x2 = int(runiform()*100)

    . replace x = -2.5 in 1

//Convert Numbers to Text//

    . num2words x, g(x_converted)

    . num2words x, g(x_rounded) round

    . replace x_converted = proper(x_rounded)

    . num2words x, g(x2_ordinal) ordinal

//Use Converted Text in Graph//

    . egen mx = mean(x)

    . num2words mx, round

    . gr bar x , over(x2_ordinal, sort(1)) ///

        note( X for Obs 2 is `=x_rounded[2]') ///

        text(60 20 `"Mean is `=mx2'"', box )

Get num2words from SSC Archives





ralpha.ado

-ralpha- generates random string characters for Stata.  Often when setting up fake, random data for an example or simulation, one might want to create a random string variable instead of a random numeric variable.  In many cases, you could generate the numeric variable and -tostring- it, but if you need string (alpha) characters, this package presents an easy way to obtain them.

Syntax:

ralpha [newvarname] [, Loweronly Upperonly Range(string)]

Options:

upper - random alpha from uppercase letters only

lower - default; random alpha from lowercase letters only

range() -   examples include: A/Z,  a/z, A/z(uppercase is first), a/c, A/G

         - numerical range stored in `r(num_range)'

If [newvarname] is left blank, the variable "ralpha" is created (if it doesn't already exist). 

Examples:

**********************!

which ralpha                       //<--  see instructions

//Example 1 //

clear 

set obs 20

ralpha                           //nothing specified-new var named "ralpha" by default

ralpha lowerdefault,             //no options specified - default is lowercase

ralpha upper, upperonly

ralpha lower, low

li

//Example 2: Using the range() option //

**Note: range goes from a/Z (a to Z)

clear

set obs 20

ralpha somerange, range(A/z)

ralpha, range(B/g)

    di in white "`r(num_range)'"      //Here's numerical range equiv. of "B/g"

//Example 3: create random words/strings in a loop //

clear

set obs 50

g newword = ""

loc lnewword 5                  //how many letters in new word?

forval n = 1/`lnewword' {

ralpha new, upp

replace newword = newword + new

drop new

}

**make newword proper**

replace newword = proper(newword)

**********************!

 

Get -ralpha- from SSC





usepackage.ado

usepackage finds and installs user-written packages that are needed to run a do-file. When sharing a do-file that contains calls to user-written commands from SSC or elsewhere, you can use usepackage to include a list of packages rather than writing a series of net install or ssc install commands to install a list of user-written packages (or instructing the user to find and install a list of packages via commands like findit or search). 

usepackage is particularly useful when user-written packages come from locations other than the SSC Archives because usepackage first searches the SSC and then if it does not find a match it searches other internet locations (e.g., those searched by net search by default), including but not limited to user-written additions published in the Stata Journal (SJ) and the Stata Technical Bulletin (STB).

Syntax:

usepackage pkgnames [ , update nearest ]

Options:

  update forces usepackage to update all user-written commands specified in pkgnames if they are already

        installed.

    nearest specifies that, after looking for an exact match for each command listed in pkgnames on SSC and other

        internet locations searched by net search, usepackage should install its best match of a similar package

        name found in a net search (that is, packages with words in the title or description matching the unmatched

        command in the pkgnames list). For example, the command:

            usepackage statplo

 

        would return no matches; however, if you also specified the nearest option, usepackage would find and

        install the user-written package statplot as the nearest match.

Remarks

    If usepackage does not find a match for a command in the pkglist in the SSC Archives, it next searches other

    internet locations searched by net search.  In doing so, usepackage produces the full net search output in the

    Results window. Currently, this output cannot be surpressed.  The reason for this is that usepackage searches

    for the matching packages and descriptions in a log-file of this output.  Further, this output cannot be

    surpressed by running usepackage quietly (doing so will produce an error).

    usepackage is partly inspired by the LaTeX command with the same name (\usepackage{}) and similar

    functionality.

Examples:

**********************!

// Setup //

  ** Uninstall user packages statplot and bacon

    . cap ado uninstall statplot //uinstall package statplot

    . cap ado uninstall st0197 //uninstall package bacon

  ** Specify that usepackage is installed from SSC

    . cap ssc install usepackage

        

// Install a list of user packages from various internet locations //

    . usepackage estout dropmiss rtfutil ralpha mac_unab

// Install missing package statplot (from SSC) //

    . usepackage statplot

// Install missing package bacon (aka package st0197) (from Stata Journal) // 

    . usepackage bacon

   ** Alternatively:

    . usepackage st0197, update

// Install and Update packages, including near-matches, from various locations //

    . usepackage tabou dropmis num2wor, near up

**********************!

Get -usepackage- from SSC





cdropmiss.ado 

-cdropmiss- allows you to drop observations or variables based on how much missingness there is in the observation or variable.  So, if you have a dataset where you know for certain that you do not want to keep variables or observations that are highly missing you can specify the level of missingness that would cause them to be removed from the dataset (e.g., 90% missing or 50% missing).

The syntax is:

syntax [varlist], [Obs Pct(real 90) ]

Options:

pct() -      option to specify how missing a variable/observation must be in order to drop it.  Default is 90% missing.

obs -        option to search for missings by observation/record rather than by variable/column

varlist -    if varlist is not specified, all variables are considered.

This idea is similar to Nick Cox's -dropmiss- except it allows for the user to set the condition of how missing a variable or observation should be if it is dropped (& NJC's code in -dropmiss- is much better written).  Using the default syntax of -dropmiss [varlist]- or specifying the pct() option to 100 should be the same as running NJC's -dropmiss- (except -dropmiss- has some additional options for handling string trimming, PIASMs, and if/in conditions that not options in -cdropmiss-).

Examples:

**************************!

which cdropmiss

//Example 1: Dropping Variables//

**setup**

sysuse auto, clear

replace make = "" in 1/10

g test = .

g test2 = 1 in 1/5

**cdropmiss**

 cdropmiss make price

cdropmiss te*

cdropmiss, p(50)

cdropmiss, p(10)

//Example 2: Dropping Observations//

**setup**

sysuse auto, clear

set obs `=_N+5'  //<-- Creates 5 Blank Rows

**create partially missing row in 1**

foreach v in pri mpg head turn displ trunk wei {

replace `v' = . in 1

}

**cdropmiss**

cdropmiss , obs p(90)

cdropmiss mpg price turn make, obs  p(100)

cdropmiss, obs   

cdropmiss, obs p(10)

**************************!

Get -cdromiss.ado-




validemail.ado

This program will validate a variable/column of email addresses in your Stata dataset. There are two checks that it performs:

            "^([0-9a-zA-Z\.-_])+[@]+([0-9a-zA-Z\.-]*[\.]+[a-zA-Z]*)"

Syntax:

   validemail variable [, GENerate(name) DNS(name) IP(name) Mergereport regex(string)] 

By default, this program will create 3 variables:  validated_email (contains the regex() validated version of the email address in variable), validated_dns (contains the valid DNS), validated_ip (contains the IP address of the valid DNS).  These variable names can be changed with the generate(), dns(), and ip() options.

Options:

generate() - renames the variable containing the regex() validated email addresses in variable

dsn() - renames the variable containing the valid DSN from the 'nslookup'

ip() - renames the variable containing the IP address of the valid DNS

mergereport - reports the number of valid email addresses with valid DNS results

regex() - allows the user to edit the regex() used to validate and correct the email addresses. For example, if the user wished to allow for a dollar sign ($) in the valid email addresses, she would specify the command:

     validemail v1, regex(`"^([0-9a-zA-Z\.-_$])+[@]+([0-9a-zA-Z\.-]*[\.]+[a-zA-Z]*)"')

Examples:

**********************!

which validemail

//example data to -input-//

clear

inp str40 v1 

"NotAnEmail " 

"@NotAnEmail " 

"@example.com " 

"!def!xyz%abc@mail.com " 

"_Yo_Yo@msn.com " 

"~@example.com " 

".wooly@example.com " 

"wo..oly@mail.com " 

"who.@example.com " 

".@zzhhzzzzhhhzzzzz.com " 

"Joe_Powers@mail.com " 

"John.Smith@test.a.rr.com " 

"John.Smith@dshs.state.tx.us " 

"John Smith@yahoo.com " 

"John Smith@ppri.tamu.edu "

end 

**

validemail v1

validemail v1, gen(testt) dns(testdns) ip(i) //rename output vars//

validemail v1, regex(`"^([0-9a-zA-Z\.-_$])+[@]+([0-9a-zA-Z\.-]*[\.]+[a-zA-Z]*)"')

Get -validemail.ado- 





writeinput.ado

This program allows you to quickly create a do-file that includes an example or snapshot of your dataset that can be -input- from the .do file.  

So, if you want to transmit an example dataset (or subset of your data) to others in a do-file(.do) or in a Statalist posting, you can use -exampledata- to write the code to a -input- statement that includes your data or subset of your data.  

-writeinput- will write the variable formats to the variable names part of the -input- statement and it will place double quotes around all string variables.  

Syntax:

 writeinput varlist [if] [in/] using "newdofile.do"  [, Replace noCLEAR Notes ]

Note:  you must name the new file with .do file extension

Options:

Replace -  replace existing do-file

notes - adds a note to the new do-file 

clear -  insert a -clear- command to the top of the new do-file.  Clear is the default, type noclear to avoid adding the -clear- command for when you want the -input- command to add data to existing data.

Examples:

**********************!

which writeinput  

sysuse auto, clear

g make2 = make

writeinput make mpg price for in 1/5 using "test1.do", r n noclear

writeinput make mpg price for if for==0 using "test2.do", r n

writeinput make price for make2 price mpg if for==1 ///

& pri>200 in 1/50 using "test3.do", r 

type "test3.do" //<-- type the saved file

Notes

       19-March-2011  Updated -writeinput- to fix a bug which caused the program to sometimes skip writing data stored in observations 3 through 9.

Get writeinput from SSC Archives





group.ado 

-group.ado- is a quick alternative to using -egen, group()- for creating a variable counting up the groups identified by a [varlist].  

Syntax is:

group [varlist] [if] [in]

Examples:

**********************!

 which group.ado

//Example 1: Single Variable to Group by//

sysuse auto, clear

keep rep78 for

**syntax 1**

group mine2 = rep78

group mine = rep78 if for==1

//Example 2: Grouping by 2 or More Variables//

sysuse auto, clear

keep rep78 for

group minenew1 = rep78 for

group minenew2 = rep78 for if for==1

**********************!

Get -group.ado-   


google.ado - Google from Stata  (deprecated)

*! due to updates in html that google search returns in Fall 2018, google.ado stopped functioning -- there is a new version (contact me) that fixes these changes if you're willing to beta test it. 


This ado-file allows you to Google something from the Stata command line and have the results either return to you in the Stata "Results" window (default) or export to your system's browser.  Syntax is:

 google <anything> [ , Filetype(string) Site(string) STATAlist  Browser  Chrome]

where [options] are defined as:

Filetype  -  Specify the filetype to search for.  E.g., pdf, txt, doc, gif, etc.

Site  -    Specify the site/domain to search within.  E.g., www.google.com, http://www.nyt.com

Statalist -    Search within Statalist archives only (via http://www.stata.com/statalist/archive/)

Browser    -    Issues Google search to system's default browser rather than the Results Window (default)

Chrome  -  (For Mac OSX only) Will redirect browser command to Chrome Browser, if installed

-google- requires that the package -intext- (downloadable from SSC or using -ssc install intext-) is installed.  -google- will auto-detect and install -intext- from web-aware Stata during its initial run.

Examples:

**1.  Most useful if issued from the Stata Command Window**

google my test search

google "my test search"

google my+test+search

/*

Then you can click any of the returned results to open the webpage in your browser.

It only returns the top 10 results right now, but I'm trying to improve the speed of it before I allow it to render more search results.

*/

**2.  It also understands how to search for certain file types**

google test search, filetype(pdf)

google test search, file(xls)

**3.   and you can send it to open in your default browser instead**

google test+search, browsergoogle test search, browser filetype(txt)

**4.  search Statalist Archives**

google "ttest error", stata

**5.  search any website/domain**

google "top headlines", site(www.nyt.com)

**6.  or for a MacOSX with Chrome installed**

google test search, chrome


Get -google.ado-  




allssc.ado

- allssc.ado- is package to bulk install SSC files.  

It is probably most useful for quickly installing many SSC user-written packages on a new machine or installing many user-written packages from SSC on a secure machine that won't have future internet access.   

You can use the package to install all SSC packages (this will take a while and several people have already pointed out why that might be a bad idea), or you can download all packages by an author, by rank (e.g., top # of hits or top 10 or top 200 packages), or by date-updated (e.g., since 2010). 

Syntax:

allssc, [ OVERwrite TOP(numeric)  ///

SINCEYEAR(numeric) HITs(numeric) ///

AUthor(string) ALL ]

Options:

 overwrite - overwrite currently installed package (sim. to (but slower than) -adoupdate-)

 top(numeric) - download the top or most downloaded packages (so, top(100) downloads the top 100 packages from last month)

 sinceyear(numeric) - download all packages updated since year specified (e.g., sinceyear(2009))

 hits() - download all packages with at least X hits/downloads from SSC last month

 author(authorname) - download all packages by authorname (e.g., author(Booth))

 all - download all auxillary/associated files for a package (same as specifying "all" option to command -ssc install pkgname, all-)

Examples:

**********************!

// Install Everything from SSC //

allssc

// Install Everything, Overwriting current package and installing all ancillary files//

allssc, overwrite all   

// Install Everything from Author "Booth" //

allssc,  author(Booth)

// Install Everything from Booth Ranked in the Top 100 and updated since Jan 1, 2011 //

allssc, overwrite all sinceyear(2011) top(200) author(Booth)  

**********************!

Download -allssc- from Google Code Repository (place it in your adopath to run)

masksmallN.ado

constants2chars.ado & chars2constants.ado

removetags.ado

Stata package to remove field tags and reshape  field tagged records where each records spans across multiple rows.  This package is useful for cleaning (scraping) data from field-tagged data on webpages.  See this post in /research_notes for more.

Syntax:

removetags  using/  , RECordstart(str) FIELDTAGDelimiter(str) [KEEP(str) REMOVEchars(str) ]

Options:

recordstart() - must contain the field tag that begins each record

fieldtagdelimiter() - must contain the char that delimits the field tag (default is a space char)

keep() - is optional list of fieldtags that will be kept in reshaped file

removechars() - is an optional list of problematic non-alphanumeric chars that need to be removed from your field tags 

        ((note: use the -charlist- program -ascii- (from SSC) to help identify these, if they exist))

Examples:

***********************!

clear

which removetags

//example 1//

removetags using "http://dl.dropbox.com/u/428249/websci.txt", ///

rec("PT") fieldtagd(" ") keep(AU UT JI CR*)

li

//example 2//

removetags using "http://dl.dropbox.com/u/428249/endnote.txt", ///

rec("Reference Type") fieldtagd(":")

li record Year Author Title in 1/10

***********************!

Get -removetags.ado- (warning: in early-beta)



iStata.ado

Archived/deprecated program to run Stata commands from iPhone (or other device) and get results when used in conjunction with Dropbox, Applescript, and a Mac OSX machine.  Contact me if you are interested in testing and installing this ecosystem.

 


slideviewer.ado 

Stata module to view my class slides that are programmed to display in the Stata Viewer.   

slideviewer allows for subdirectory navigation of directories to display SMCL files in Stata.

    This can be used to show a series of linked SMCL files (like in a slideshow or presentation using

    the Viewer) that are stored in sub-directories.  The post option can used to post results or

    tracking information in r-class scalars that can be used to make the slide more interactive (like

    in a interactive tutorial presented in a series of Viewer slides ).

To install -slideviewer- from SSC, type into your Command window:

ssc install slideviewer, replace

__

Alternatively, Download from the link below or from my PHPM 672 class webpage:

slideviewer.ado



itunes.ado - iTunes control from Stata

This ado-file allows Stata for Mac OSX users to control itunes without having to leave the Stata command line.  Syntax is:

   itunes <subcommand>

 where <subcommand> includes one of the following:  

   play, pause, stop, nowplaying, next, next track, previous, prev track, info

   playlists, playlist <playlistname>, stream (url streaming/radio), help

   volup, voldown, volmax, volmin, mute, unmute, shuffle, unshuffle 

 iTunes for Stata also has a control prompt that pops up after typing any of the commands above.  This control lets you click to control iTunes directly from Stata.  

Get -itunes.ado



blackjack.ado

Blackjack game for Stata.  This was one of the first programs I wrote for Stata & so it's probably buggier than most of my other programs (but it's a nice mindless game that can be played from the Stata console).  

The syntax is simply -blackjack- 

You get $500 the first time you play when Stata starts and this this total carries across games (you lose your $ when you restart/exit Stata). 

You'll be prompted to bet, hit, or stay (type your response into the command window and press "return"). The computer will always play if it has less than 13 and less than the player.

Enjoy!

Get -blackjack.ado-




cls.ado - Stata module to clear the Results window/screen

Inspired by a question from Jim Fish.  This program will clear the results window/screen much like the 'cls' command line program in MSDOS. 

When you specify the 'logo' option the same logo and information that appears when Stata starts will reappear on screen.

Download cls.ado


countdown.ado  - Stata module countdown minutes remaining 

Use the syntax:

    countdown date/time

where date/time is formatted :  DD Mon YYYY HH:MM:SS (sim. to  a Stata timestamp from -clist return-)

Example:

countdown  21 Mar 2012 17:15:00

Download countdown.ado




Mac OSX / *NIX

Applescripts for MacOSX

My Posts at Stack Overflow

Here is some software I've written for the Mac OSX platform:

Dual_Finder (.app/.scpt)

Mac OSX (10.4 or later) application/script to open two (or more) Finder.app windows stacked vertically to easily move/copy/paste/examine files in two folders.  The finder window stacked on the left (Window 1 below) is set to "list view"; Finder Window 2 (right) is set to "column view."  Adjust the size of the Finder windows using the "hei"(height) and "wid"(width) properties.  The script will also "hide" all other open windows.

You can download the .app version of this file (below) and then drag it to the dock next to your Finder.app icon for a convenient way to open and positioning multiple Finder windows. 

Here's the .script:

property wid : 10

property hei : 40

set the startup_disk to (path to startup disk)

tell application "Finder"

close every Finder window

activate

set visible of (every process whose visible is true and frontmost is false) to false

         ---get the target of the 1st Finder window

                 --Window 1--

set win to make new Finder window

set the target of win to the folder "Desktop" of the home

set the bounds of win to {hei, wid, (hei + 650), (wid + 750)}

set the current view of win to list view

                 --Window 2--

set win to make new Finder window

set the target of win to the folder "Documents" of the home

set the bounds of win to {(hei + 660), (wid), (hei + 1400), (wid + 750)}

set the current view of win to column view

select the last Finder window

        ----close the first Finder window

end tell

Get dual_finder.scpt 

Get dual_finder.app 

ALFRED.app Scripts

Note:  Go to this page to learn about how to install Alfred.app scripts using PowerPack.

  1. Clear 10.7 Lion "Saved Application States" using Alfred.app

Mac OSX Lion has a "save application states" function that recalls the properties (size, location, documents open, etc) of application windows when you close an application or shut down the computer.  While this can be helpful for quickly reopening documents and applications, sometime Lion remembers applications with a error or issues that you'd rather it forget.  If you are an Alfred Powerpack user, you can download and install this script which activates the command "clearsas" which will clear the "Saved Applications States" folder in your (hidden) Library.

Download clearsas.alfredextension

 

 2. Hide or Show Desktop Icons using Alfred.app

Script to quickly hide or show all desktop icons by typing the commands "desktopon" or  "desktopoff"  in Alfred.

Download:

desktopON.alfredextension

 and 

desktopOFF.alfredextension

iStata.scpt - Stata for your iPhone

Get Results from Stata on your iPhone using the process described below and on this /research_notes post.

This requires 5 components:  

(1) Stata (10 or later) installed on a Mac OSX (10.5 or later) 

(2) A Dropbox account linked to your Mac that has Stata installed

(3) iStata.scpt Applescript file to manage files put in Dropbox  

(4) iStata.ado to run the file, log the output, and put it back in Dropbox

(5) the free application Plaintext for iPhone (or some equivalent) to write and view .do files written and run from your iPhone

Setup:

You'll need to save the iStata.scpt and iStata.do files into the folders referenced in these scripts in your Dropbox folders on your Mac OSX.  Really, you can place these files/folders anywhere in your Dropbox that you'd like, but you need to change the paths in these scripts to point to the proper location.

The basic idea of the workflow is illustrated below.  Basically, the process is:

  

(1) you create text file (called "torun.txt") of Stata commands in Plaintext.app on your iPhone which is linked to your Dropbox account  

(2) Once this text file ("torun.txt") is saved in your Dropbox account, your Mac OSX runs iPhone.scpt which converts the file to a .do file ("torun.do") and runs iStata.ado.  

(3) iStata.ado creates a logfile, runs the "torun.do" commands, logging the output, and saves the results as "Results.txt" the "Results" subfolder in Dropbox

(4) "haverun.do" replaces "torun.txt" in your iPhone Dropbox/Plaintext folder so that you can see what you ran (that is, the "torun.txt"/"torun.do" file is erased and replaced by "haverun.do" in your Dropbox and the results are placed in the "Results" subfolder on Dropbox and the file is named "Results.txt").  

(5) Each time you create and save "torun.txt", "haverun.do" and "Results.txt" are created and "torun.txt" is erased.

killall_shutdown (.scpt/.app) - Close all open applications and shutdown

Script to quit all applications open/visible on a Mac OSX and shutdown the machine.  This is also available as a application (.app) package.  Whereas most scripts like this usually just issue a "KillAll" to all programs (via osascript or some other equivalent), this one tries to issue a "quit" command to programs to properly close them.  Save this script or app to your dock and you can quickly close all programs and shutdown your Mac in one click.

Here's the .scpt code:

tell application "System Events"

set allproc to name of every application process whose visible is true

repeat with i from 1 to count items of allproc

tell application tproc to quit

end repeat

shut down

end tell

Get killall_shutdown.scpt

Get kilall_shutdown.app

PDF2TXT.scpt

This program will allow you to strip the text from a pdf of any file dropped in the target folder.  Simply attach this as a folder action and then copy/paste the file into this folder to run the script.

Get PDF2TXT

end try

set tproc to item i of allproc

try