<?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>Michael Ewens &#187; code</title>
	<atom:link href="http://michaelewens.com/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://michaelewens.com</link>
	<description>Tepper School of Business, Carnegie Mellon Univ.</description>
	<lastBuildDate>Tue, 10 Jan 2012 19:00:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Create a dated log file in Matlab</title>
		<link>http://michaelewens.com/2009/07/23/create-a-dated-log-file-in-matlab/</link>
		<comments>http://michaelewens.com/2009/07/23/create-a-dated-log-file-in-matlab/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 16:33:32 +0000</pubDate>
		<dc:creator>Michael Ewens</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://michaelewens.com/2009/07/23/create-a-dated-log-file-in-matlab/</guid>
		<description><![CDATA[If you change your datasets or code a lot in Matlab, it is smart to keep track of the results over time (trust me&#8230;.). The &#8216;diary&#8217; function allows you to record all output of your scripts to a file. Append your main .m file with the following code to create a diary/log file that is [...]]]></description>
			<content:encoded><![CDATA[<p>If you change your datasets or code a lot in Matlab, it is smart to keep track of the results over time (trust me&#8230;.).  The &#8216;diary&#8217; function allows you to record all output of your scripts to a file.  Append your main .m file with the following code to create a diary/log file that is uniquely dated to the time (to the minute) that you ran the script:</p>
<p><code>date_now = clock;</code><br />
<code>date_now = strcat(num2str(date_now(1)),'_',num2str(date_now(2)),'_', num2str(date_now(3)), num2str(date_now(4)), num2str(date_now(5)));</code><br />
<code>diary(strcat('log', date_now,'.log'));</code></p>
]]></content:encoded>
			<wfw:commentRss>http://michaelewens.com/2009/07/23/create-a-dated-log-file-in-matlab/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Plot multiple kernel densities on one plot in Stata</title>
		<link>http://michaelewens.com/2009/03/23/plot-multiple-kernel-densities-on-one-plot-in-stata/</link>
		<comments>http://michaelewens.com/2009/03/23/plot-multiple-kernel-densities-on-one-plot-in-stata/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 08:35:07 +0000</pubDate>
		<dc:creator>Michael Ewens</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[plotting]]></category>
		<category><![CDATA[stata]]></category>

		<guid isPermaLink="false">http://michaelewens.com/?p=167</guid>
		<description><![CDATA[If you want to compare kernel density estimates across years for a particular variable, putting each estimate on one graph will make it easy. The process is fairly straightforward in Stata (and even easier in Matlab…). First, we start with the simple ‘kdensity‘ command kdensity income if year == 1990 Next, we append this command [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to compare kernel density estimates across years for a particular variable, putting each estimate on one graph will make it easy. The process is fairly straightforward in Stata (and even easier in Matlab…). First, we start with the simple ‘kdensity‘ command</p>
<p><code>kdensity income if year == 1990<br />
</code><br />
Next, we append this command with the ‘addplot‘ function:</p>
<p><code>kdensity income if year == 1990, addplot(kdensity income if year == 1991)<br />
</code><br />
and we can add even more with the ‘||’ syntax:</p>
<p><code>kdensity income if year == 1990, addplot(kdensity income if year == 1991 || kdensity income if year == 1992)</code></p>
<p>If we could use the ‘by’ option, this process would be much cleaner. Finally, we add a legend:</p>
<p><code>kdensity income if year == 1990, addplot(kdensity income if year == 1991 || kdensity income if year == 1992) legend(ring(0) pos(2) label(1 "1990") label(2 "1991") label(3 "1992"))</code></p>
]]></content:encoded>
			<wfw:commentRss>http://michaelewens.com/2009/03/23/plot-multiple-kernel-densities-on-one-plot-in-stata/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Strings to unique integers in Stata</title>
		<link>http://michaelewens.com/2009/03/22/strings-to-unique-integers-in-stata/</link>
		<comments>http://michaelewens.com/2009/03/22/strings-to-unique-integers-in-stata/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 08:33:03 +0000</pubDate>
		<dc:creator>Michael Ewens</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[stata]]></category>

		<guid isPermaLink="false">http://michaelewens.com/?p=165</guid>
		<description><![CDATA[Suppose you have a string variable with a finite number of values (e.g. US states, industry, etc). The encode command plus the generate command will create a new variable that assigns unique ids to each string value: encode your_string_variable, gen(new_string_as_int) The labels in the edit/browse view will look like strings, so make sure you use [...]]]></description>
			<content:encoded><![CDATA[<p>Suppose you have a string variable with a finite number of values (e.g. US states, industry, etc).  The encode command plus the generate command will create a new variable that assigns unique ids to each string value:</p>
<p><code>encode your_string_variable, gen(new_string_as_int) </code></p>
<p>The labels in the edit/browse view will look like strings, so make sure you use ‘nolabel’ on any export or tab commands.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelewens.com/2009/03/22/strings-to-unique-integers-in-stata/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stata to Mysql: Escaping Quotes</title>
		<link>http://michaelewens.com/2009/03/16/stata-to-mysql-escaping-quotes/</link>
		<comments>http://michaelewens.com/2009/03/16/stata-to-mysql-escaping-quotes/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 23:40:48 +0000</pubDate>
		<dc:creator>Michael Ewens</dc:creator>
				<category><![CDATA[economics]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[stata]]></category>

		<guid isPermaLink="false">http://michaelewens.com/?p=120</guid>
		<description><![CDATA[If you use multiple linked databases or tables, I highly recommend linking mysql and Stata for both data merging and analysis. You can store the data in one clean place with relational tables and have all of Stata&#8217;s capabilities at hand with the odbc command. Before you start running &#8220;odbc insert&#8221; commands, you have to [...]]]></description>
			<content:encoded><![CDATA[<p>If you use multiple linked databases or tables, I highly recommend linking mysql and Stata for both data merging and analysis.  You can store the data in one clean place with relational tables and have all of Stata&#8217;s capabilities at hand with the <a href="http://www.stata.com/help.cgi?odbc">odbc command</a>.  Before you start running &#8220;odbc insert&#8221; commands, you have to make sure the data is compatible with SQL queries.  This means all strings need the quotes escaped.  I was doing so many of these escapes that I wrote an ado file to simplify the process.</p>
<p><a href='http://michaelewens.com/wp-content/uploads/2009/03/escape_all_quotes.ado'>Download: escape_all_quotes</a></p>
<p>The script loops through all the variables in your dataset, checks if each is a string and if so, escapes any quotes.  Although it has worked for 1000s of my &#8220;odbc insert&#8221;s, their could be bugs or speed improvements.  Let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelewens.com/2009/03/16/stata-to-mysql-escaping-quotes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

