<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Stata Things &#187; syntax</title>
	<atom:link href="http://enoriver.net/index.php/tag/syntax/feed/" rel="self" type="application/rss+xml" />
	<link>http://enoriver.net</link>
	<description>computing for fun and profit</description>
	<lastBuildDate>Mon, 07 May 2012 13:43:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Count missing observations</title>
		<link>http://enoriver.net/index.php/2010/03/16/count-missing-observations/</link>
		<comments>http://enoriver.net/index.php/2010/03/16/count-missing-observations/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 02:54:59 +0000</pubDate>
		<dc:creator>Gabi Huiber</dc:creator>
				<category><![CDATA[Stata]]></category>
		<category><![CDATA[missing()]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://enoriver.net/?p=1144</guid>
		<description><![CDATA[With one variable, that's easy enough: count if missing(variable-name). If you have several variables, you can put them in a foreach loop. But if you have to do this for arbitrary lists of variables in several files, it may be interesting to package that foreach loop inside a quick command that might handle special display [...]]]></description>
			<content:encoded><![CDATA[<p>With one variable, that's easy enough: <code>count if missing(<em>variable-name</em>)</code>. If you have several variables, you can put them in a foreach loop. But if you have to do this for arbitrary lists of variables in several files, it may be interesting to package that foreach loop inside a quick command that might handle special display instructions as well. </p>
<p>Here is one suggestion:</p>
<p><code>
<pre>
// countIfMissing: display the total count of observations, then
// any counts of missing observations for each variable in a list.
capture prog drop countIfMissing
program countIfMissing

version 11
syntax varlist

quietly count
local count=r(N)

// now make things align nicely
local sum=`count'
local tens=1
while `sum'/10>1 {
   local sum=`sum'/10
   local tens=`tens'+1
}
local width=`tens'+int(`tens'/3)
local varct: list sizeof varlist

di ""
di "Observations:"
di %`width'.0fc `count'
di ""
di "Missing:"
foreach varble in `varlist' {
   qui count if missing(`varble')
   local ct=r(N)
   local pct: di %4.2fc 100*`ct'/`count'
   if `pct'>0 {
      di %`width'.0fc `ct' " `varble' (`pct'%)"
   }
   else {
      local varct=`varct'-1
   }
}
if `varct'==0 {
   local offset=`width'+2
   di _column(`offset') "none of `varlist'"
}
di ""

end
</pre>
<p></code></p>
<p>For an example of usage, you can try this:</p>
<p><code>
<pre>
sysuse auto
local myvars "make price foreign"
countIfMissing `myvars'
countIfMissing m*       // (1)
countIfMissing _all     // (2)
</pre>
<p></code></p>
<p>As you can see in (1) and (2), the usual varlist conveniences apply here. </p>
]]></content:encoded>
			<wfw:commentRss>http://enoriver.net/index.php/2010/03/16/count-missing-observations/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>I switched to Vim</title>
		<link>http://enoriver.net/index.php/2010/02/26/i-switched-to-vim/</link>
		<comments>http://enoriver.net/index.php/2010/02/26/i-switched-to-vim/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 17:08:34 +0000</pubDate>
		<dc:creator>Gabi Huiber</dc:creator>
				<category><![CDATA[Stata]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[text editors]]></category>
		<category><![CDATA[Vim]]></category>

		<guid isPermaLink="false">http://enoriver.net/?p=1040</guid>
		<description><![CDATA[I was looking for an excuse to try something new and I decided to pick on one Notepad++ shortcoming that was handy: the Stata syntax highlighting gets utterly mangled after compound quotes -- `"`like so'"' -- which do sometimes arise, usually in the process of file open/file write.  Vim does not get confused by compound quotes [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking for an excuse to try something new and I decided to pick on one <a href="http://notepad-plus.sourceforge.net/uk/site.htm">Notepad++</a> shortcoming that was handy: the Stata syntax highlighting gets utterly mangled after compound quotes -- `"`like so'"' -- which do sometimes arise, usually in the process of file open/file write. </p>
<p><a href="http://www.vim.org/">Vim</a> does not get confused by compound quotes and it comes with Stata syntax highlighting out of the box. Integrating it with Stata is not hard at all, either. There are some general directions by Nick Cox <a href="http://fmwww.bc.edu/repec/bocode/t/textEditors.html#vim">here</a>, but on my Windows XP machine I just had to do two things.</p>
<p>First, I had to edit the PERSONAL/e/editors.ado file to make Vim replace Notepad++ entry in the Editors... sub-menu of the User menu:</p>
<p><code>
<pre>
program define editors
	version 10
	window menu append submenu "stUser" "Editors"
	window menu append item "Editors" "Vim" "winexec gvim.exe"
end
</pre>
<p></code></p>
<p>Next, I wrote a PERSONAL/v/vim.ado file like so:</p>
<p><code>
<pre>
program vim
	version 10
	syntax anything
	winexec gvim.exe `anything'
end
</pre>
<p></code></p>
<p>This is based on Nick Cox's recipe, slightly altered so you can launch Vim from the Stata command line to edit an existing do-file that say has spaces in it, as in <code>vim "my dofile.do"</code>. There's a little more on this "syntax anything" solution in my<a href="http://enoriver.net/index.php/2010/02/23/calling-irregular-arguments-with-syntax-anything/"> previous Stata post</a>.</p>
<p>One thing I did give up -- for now -- is the ability to launch a Stata instance from within Vim after I'm done editing a do-file, either for running the entire do-file or some select lines, the way I used to be able to do in Notepad++. There's got to be a way for that, though. If you know it, please drop me a line.</p>
<p>That said, I'd never knock Notepad++. It is still a fine text editor that has served me well. The people at <a href="http://mathereconomics.com/">Mather Economics</a>, who adopted it a while back at my instigation, are sticking with it -- and I recommend it to anybody who does not insist on a modal editor.</p>
]]></content:encoded>
			<wfw:commentRss>http://enoriver.net/index.php/2010/02/26/i-switched-to-vim/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Calling irregular arguments with syntax anything</title>
		<link>http://enoriver.net/index.php/2010/02/23/calling-irregular-arguments-with-syntax-anything/</link>
		<comments>http://enoriver.net/index.php/2010/02/23/calling-irregular-arguments-with-syntax-anything/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 17:04:39 +0000</pubDate>
		<dc:creator>Gabi Huiber</dc:creator>
				<category><![CDATA[Stata]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://enoriver.net/?p=1031</guid>
		<description><![CDATA[The other day I wrote a program that needed to call a file as an argument -- with the full file path. My first pass at it was to capture the argument as usual, with say args input_file. But that would not have worked with file paths that have spaces in them. What might have [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I wrote a program that needed to call a file as an argument -- with the full file path. My first pass at it was to capture the argument as usual, with say <code>args input_file</code>. But that would not have worked with file paths that have spaces in them. What might have worked, I guessed, was to use something like this:<br />
<code>
<pre>
syntax namelist
local input_file `namelist'
</pre>
<p></code><br />
That, however, choked on a Windows-style file path, because the colon in C:\ is an illegal name. Trial and error (and the [I] book) led me to <code>syntax anything</code>. Here's my scratchpad:<br />
<code>
<pre>
capture prog drop myHello
program myHello

syntax namelist
local names `namelist'
di "Hello `names'"

end

myHello Eenie: Meenie
</pre>
<p></code><br />
OK, so "illegal name" it is. Now let's see if "anything" might work better than "namelist":<br />
<code>
<pre>
capture prog drop myHello
program myHello

syntax anything
local names `anything'
di "Hello `names'"

end

myHello c:\my file path here\my file name here.txt
</pre>
<p></code><br />
Success. This may look trivial, but everything is after the fact. We have a long-standing policy at the Eno River Analytics worldwide headquarters that we should write toy programs for sketching things out before we go ahead and actually break something.</p>
]]></content:encoded>
			<wfw:commentRss>http://enoriver.net/index.php/2010/02/23/calling-irregular-arguments-with-syntax-anything/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

