Tuesday, October 19, 2010

Fun with Stata: Google for Stata

I use the -findit- command from the Stata command line/window dozens of times a day.  However, I've always wished that there was a way to have -findit- search for than just Stata commands or materials on the web so that I wouldn't have to leave the Stata window just to Google something.  


Also, I've always wanted -findit- to search Statalist archives for me as part of the process of looking for an answer to some burning Stata-related question.  Now, you can stay tethered to Stata and Google with impunity without ever leaving the safety of your Stata command line.

The ado-file described below 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.  The title of the results webpages are returned and the links in blue are clickable to navigate to that page in your OS default browser.



The syntax is:

 google [ , 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, browser
google 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




See my software page for more on this code & other software I've written for Stata and Mac OSX.



No comments:

Post a Comment