<?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/category/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>Using Growl with R</title>
		<link>http://michaelewens.com/2010/07/02/using-growl-with-r/</link>
		<comments>http://michaelewens.com/2010/07/02/using-growl-with-r/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 19:46:03 +0000</pubDate>
		<dc:creator>Michael Ewens</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[growl]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[r]]></category>

		<guid isPermaLink="false">http://michaelewens.com/?p=673</guid>
		<description><![CDATA[If you have a long R script and would like to be notified when computation is complete, follow these directions to get Growl notifications: Install Growl and leave the disk image open. Open Terminal. Run &#8220;cd /Volumes/Growl-1.2/Extras/growlnotify&#8221; Run &#8220;./install.sh&#8221; Then follow these directions to get your R script to talk to Growl by adding something [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a long R script and would like to be notified when computation is complete, follow these directions to get Growl notifications:</p>
<ol>
<li><a href="http://growl.info/index.php">Install Growl</a> and leave the disk image open.</li>
<li>Open Terminal.</li>
<li>Run &#8220;cd /Volumes/Growl-1.2/Extras/growlnotify&#8221;</li>
<li>Run &#8220;./install.sh&#8221;</li>
</ol>
<p>Then <a href="http://snippets.dzone.com/posts/show/2638">follow these directions</a> to get your R script to talk to Growl by adding something like:<br />
<code>    system(paste("growlnotify -a R -t \"R is done\" -m", "\"Inserted the data\"", sep=""))<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://michaelewens.com/2010/07/02/using-growl-with-r/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Stata, ODBC and date columns</title>
		<link>http://michaelewens.com/2010/05/23/stata-odbc-and-date-columns/</link>
		<comments>http://michaelewens.com/2010/05/23/stata-odbc-and-date-columns/#comments</comments>
		<pubDate>Sun, 23 May 2010 06:32:13 +0000</pubDate>
		<dc:creator>Michael Ewens</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ado]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[stata]]></category>

		<guid isPermaLink="false">http://michaelewens.com/?p=648</guid>
		<description><![CDATA[Stata has a ton of flexilbility for creating and manipulating dates. However, if you want to save Stata data to an external database (e.g. Accesss, PostgreSQL, MySQL, etc.) the numeric date format in Stata will be difficult to interpret outside the program. My use case involved working with Stata to merge and clean some data [...]]]></description>
			<content:encoded><![CDATA[<p>Stata has a ton of flexilbility for <a href="http://www.stata.com/help.cgi?dates_and_times">creating and manipulating dates</a>.  However, if you want to save Stata data to an external database (e.g. Accesss, PostgreSQL, <a href="http://www.mysql.com/">MySQL</a>, etc.) the numeric date format in Stata will be difficult to interpret outside the program.  My use case involved working with Stata to merge and clean some data that was pushed to a MySQL database with <a href="http://www.stata.com/help.cgi?odbc">odbc</a> and later loaded in <a href="http://www.r-project.org/">R</a> with its <a href="http://cran.r-project.org/web/packages/RODBC/index.html">odbc functionality</a>.  It was in the last step that I learned of Stata&#8217;s dating conventions when writing to external databases.  So <a href="http://www.stata.com/statalist/archive/2010-05/msg01190.html">I asked the Stata list</a>.</p>
<p>A <a href="http://www.stata.com/statalist/archive/2010-05/msg01201.html">very helpful subsciber</a> presented a solution very similar to one that I mocked up.  With some of the code posted on the Statalist and some new additions, I present <a href="http://pastebin.com/8ywbft1S">odbc2create</a>. UPDATE: I fixed an issue when dealing with a database with no dates and had to add a loop.</p>
<p>This modified odbc command does the following:</p>
<ul>
<li>searches all your variables for dates (they must be formatted as such or Stata&#8217;s ability to detect them is impossible)</li>
<li>converts those dates to the YYYY-MM-DD format</li>
<li>inserts the dates into your mysql database as strings</li>
<li>re-types those date columns in the newly created database as DATEs</li>
</ul>
<p>The best part: when you load a table created this way back into Stata, it immediately recognized the DATEs as dates.  I hope they build this functionality into Stata in the future.  One caveat (which may explain why they haven&#8217;t built it internally) is that the ALTER command in the ado file is specific to MySQL.  Someone should generalize the code to recognize the datasource engine and modify the ALTER command accordingly.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelewens.com/2010/05/23/stata-odbc-and-date-columns/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Latex regression and summary tables in Stata</title>
		<link>http://michaelewens.com/2010/04/09/latex-regression-and-summary-tables-in-stata/</link>
		<comments>http://michaelewens.com/2010/04/09/latex-regression-and-summary-tables-in-stata/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 18:17:17 +0000</pubDate>
		<dc:creator>Michael Ewens</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[eststo]]></category>
		<category><![CDATA[latex]]></category>
		<category><![CDATA[regressions]]></category>
		<category><![CDATA[stata]]></category>

		<guid isPermaLink="false">http://michaelewens.com/?p=630</guid>
		<description><![CDATA[A clean, well organized latex table is difficult to build. If you do a lot of analysis in Stata, there are several tools to output latex tables of your regressions or summary statistics. These packages do not always work perfectly with the standard options. Below I present two example code snippets to produce a latex [...]]]></description>
			<content:encoded><![CDATA[<p>A clean, well organized latex table is difficult to build.  If you do a lot of analysis in Stata, there are several tools to output latex tables of your regressions or summary statistics.  These packages do not always work perfectly with the standard options.  Below I present two example code snippets to produce a latex table of a set of regressions that includes a IV estimator and a summary statistics table that compares two groups in a database.  Each uses the <a href="http://repec.org/bocode/e/estout/">eststo package</a>.</p>
<p><strong>Regression Table with Multiple Equations and Stages</strong></p>
<p>Here I run a couple of limited dependent variable models and a two-stage bivariate probit with an IV.  The output isn&#8217;t perfect, but it works for pre-submission distribution.</p>
<p><script src="http://gist.github.com/361415.js"></script></p>
<p>The output looks like this:</p>
<p><a title="View Latex regression output from eststo on Scribd" href="http://www.scribd.com/doc/29669150/Latex-regression-output-from-eststo" style="margin: 12px auto 6px auto; font-family: Helvetica,Arial,Sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none; display: block; text-decoration: underline;">Latex regression output from eststo</a> <object id="doc_787590025690274" name="doc_787590025690274" height="500" width="100%" type="application/x-shockwave-flash" data="http://d1.scribdassets.com/ScribdViewer.swf" style="outline:none;" rel="media:document" resource="http://d1.scribdassets.com/ScribdViewer.swf?document_id=29669150&#038;access_key=key-9dxl9jdjk355kd900nw&#038;page=1&#038;viewMode=list" xmlns:media="http://search.yahoo.com/searchmonkey/media/" xmlns:dc="http://purl.org/dc/terms/" ><param name="movie" value="http://d1.scribdassets.com/ScribdViewer.swf"><param name="wmode" value="opaque"><param name="bgcolor" value="#ffffff"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><param name="FlashVars" value="document_id=29669150&#038;access_key=key-9dxl9jdjk355kd900nw&#038;page=1&#038;viewMode=list"><embed id="doc_787590025690274" name="doc_787590025690274" src="http://d1.scribdassets.com/ScribdViewer.swf?document_id=29669150&#038;access_key=key-9dxl9jdjk355kd900nw&#038;page=1&#038;viewMode=list" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" height="500" width="100%" wmode="opaque" bgcolor="#ffffff"></embed></object>	</p>
<p><strong>Summary statistics with a by variable</strong></p>
<p>Next, consider summarizing the characteristics of two groups in your data.  For example, I want to compare the age, number of boards seats and other features of venture capital spinoff founders to everyone else.  </p>
<p><script src="http://gist.github.com/361423.js"></script></p>
<p>The output will look like this:</p>
<p><a title="View Found on Scribd" href="http://www.scribd.com/doc/29669266/Found" style="margin: 12px auto 6px auto; font-family: Helvetica,Arial,Sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none; display: block; text-decoration: underline;">Found</a> <object id="doc_596590822087790" name="doc_596590822087790" height="500" width="100%" type="application/x-shockwave-flash" data="http://d1.scribdassets.com/ScribdViewer.swf" style="outline:none;" rel="media:document" resource="http://d1.scribdassets.com/ScribdViewer.swf?document_id=29669266&#038;access_key=key-2glxu6yf5sg47rimr1of&#038;page=1&#038;viewMode=list" xmlns:media="http://search.yahoo.com/searchmonkey/media/" xmlns:dc="http://purl.org/dc/terms/" ><param name="movie" value="http://d1.scribdassets.com/ScribdViewer.swf"><param name="wmode" value="opaque"><param name="bgcolor" value="#ffffff"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><param name="FlashVars" value="document_id=29669266&#038;access_key=key-2glxu6yf5sg47rimr1of&#038;page=1&#038;viewMode=list"><embed id="doc_596590822087790" name="doc_596590822087790" src="http://d1.scribdassets.com/ScribdViewer.swf?document_id=29669266&#038;access_key=key-2glxu6yf5sg47rimr1of&#038;page=1&#038;viewMode=list" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" height="500" width="100%" wmode="opaque" bgcolor="#ffffff"></embed></object>	</p>
<p>The full details of the <a href="http://repec.org/bocode/e/estout/hlp_esttab.html">esttab</a>, <a href="http://repec.org/bocode/e/estout/hlp_estpost.html">estpost</a> and <a href="http://repec.org/bocode/e/estout/hlp_eststo.html">eststo</a> have many more options and a lot of <a href="http://repec.org/bocode/e/estout/advanced.html">examples</a>.  </p>
]]></content:encoded>
			<wfw:commentRss>http://michaelewens.com/2010/04/09/latex-regression-and-summary-tables-in-stata/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Running sums in Stata</title>
		<link>http://michaelewens.com/2010/02/21/running-sums-in-stata/</link>
		<comments>http://michaelewens.com/2010/02/21/running-sums-in-stata/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 19:36:05 +0000</pubDate>
		<dc:creator>Michael Ewens</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[stata]]></category>

		<guid isPermaLink="false">http://michaelewens.com/?p=610</guid>
		<description><![CDATA[Perhaps it is bad that I didn&#8217;t know this before, but the following code for Stata would have saved a week off of my dissertation work.  Suppose that you have data structured like so: firm_id,date,amount and you want to create a new variable that is the total amount as of each date for each firm. [...]]]></description>
			<content:encoded><![CDATA[<p>Perhaps it is bad that I didn&#8217;t know this before, but the following code for Stata would have saved a week off of my dissertation work.  Suppose that you have data structured like so:</p>
<p><code>firm_id,date,amount</code></p>
<p>and you want to create a new variable that is the total amount as of each date for each firm.  In Stata, you simply type:</p>
<p><code>sort firm_id date</code><br />
<code>bysort firm_id: gen total_t = sum(amount)</code></p>
<p>Note the use of &#8216;<a href="http://www.stata.com/help.cgi?Generate">gen</a>&#8216; rather than &#8216;<em><a href="http://www.stata.com/help.cgi?egen">egen</a></em>.&#8217; The &#8216;sum&#8217; command differs by the type of generate command (i.e. gen or egen), so about 500 lines of loops written in Stata code could be condensed in a few lines.  Stata needs to fix the &#8216;egen&#8217; and &#8216;gen&#8217; distinction or I need to port more of my projects to R.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelewens.com/2010/02/21/running-sums-in-stata/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Publication quality images in Matlab</title>
		<link>http://michaelewens.com/2009/09/15/publication-quality-images-in-matlab/</link>
		<comments>http://michaelewens.com/2009/09/15/publication-quality-images-in-matlab/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 21:59:25 +0000</pubDate>
		<dc:creator>Michael Ewens</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://michaelewens.com/?p=502</guid>
		<description><![CDATA[Matlab has some great plotting tools, but the output of export of  &#8221;Save As&#8221; rarely produces consistent and clean results. Enter export_fig. The best feature is its anti-aliasing that produces clean, crisp fonts. Just download the package and add add_path('export_fig') to your m file and you can use the function. I had the best luck [...]]]></description>
			<content:encoded><![CDATA[<p>Matlab has some great plotting tools, but the output of export of  &#8221;Save As&#8221; rarely produces consistent and clean results.  Enter <a href="http://www.mathworks.com/matlabcentral/fileexchange/23629">export_fig</a>.  The best feature is its anti-aliasing that produces clean, crisp fonts.  Just download the package and add</p>
<p><code>add_path('export_fig')</code></p>
<p>to your m file and you can use the function.  I had the best luck (see example below) with the follow command:</p>
<p style="text-align: center;"><code>export_fig('figures/updates/risk_over_size.png', '-png', '-nocrop');<br />
</code><br />
<a href="http://michaelewens.com/wp-content/uploads/2009/09/selection_to_mixture.png"><img class="aligncenter size-full wp-image-503" title="selection_to_mixture" src="http://michaelewens.com/wp-content/uploads/2009/09/selection_to_mixture.png" alt="selection_to_mixture" width="672" height="411" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://michaelewens.com/2009/09/15/publication-quality-images-in-matlab/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cell arrays and strings in Matlab</title>
		<link>http://michaelewens.com/2009/09/02/cell-arrays-and-strings-in-matlab/</link>
		<comments>http://michaelewens.com/2009/09/02/cell-arrays-and-strings-in-matlab/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 02:27:10 +0000</pubDate>
		<dc:creator>Michael Ewens</dc:creator>
				<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://michaelewens.com/?p=436</guid>
		<description><![CDATA[Suppose you want to create a dynamic matrix of strings in Matlab.  For example, you might want the legend of your graph to depend on the data (which changes on a daily basis).  Cell arrays are your best bet.  However, be warned on how to access the elements of said arrays.  Suppose I have a [...]]]></description>
			<content:encoded><![CDATA[<p>Suppose you want to create a dynamic matrix of strings in Matlab.  For example, you might want the legend of your graph to depend on the data (which changes on a daily basis).  <a href="http://blogs.mathworks.com/loren/2006/06/21/cell-arrays-and-their-contents/">Cell arrays</a> are your best bet.  However, be warned on how to access the elements of said arrays.  Suppose I have a cell array constructed as follows:</p>
<p><code>names = cell(3,2);<br />
names(high_regime,: ) = [{'Probability of a home run'} {'Home Run'}];<br />
names(low_regime, : ) = [{'Probability of bankruptcy'} {'Bankruptcy'}];<br />
names(middle_regime, : ) = [{'Probability break-even'} {'Break-even'}];</code></p>
<p>If you want to access a particular element of this cell array <em>as a string, </em>you must use the curly brackets like so:</p>
<p><code>set(plot1(1),'LineStyle','-.','DisplayName',names{1,2});</code></p>
<p>If you try the standard <code>names(1,2)</code>, the function set() will not think the result is a string.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelewens.com/2009/09/02/cell-arrays-and-strings-in-matlab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a lagged sum variable in Stata</title>
		<link>http://michaelewens.com/2009/05/19/create-a-lagged-sum-variable-in-stata/</link>
		<comments>http://michaelewens.com/2009/05/19/create-a-lagged-sum-variable-in-stata/#comments</comments>
		<pubDate>Tue, 19 May 2009 09:03:11 +0000</pubDate>
		<dc:creator>Michael Ewens</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[lag operators]]></category>
		<category><![CDATA[stata]]></category>

		<guid isPermaLink="false">http://michaelewens.com/?p=367</guid>
		<description><![CDATA[UPDATE: this code is stupid. You can do this in a few lines. Although Stata has powerful lag operators for both time series and panel settings, it is difficult to construct lagged sums of variables across an unbalanced panel.  Suppose you have observations for individuals.   Each time period you observe some value like investments, [...]]]></description>
			<content:encoded><![CDATA[<p>UPDATE: this code is stupid.  <a href="http://michaelewens.com/2010/02/21/running-sums-in-stata/">You can do this in a few lines</a>.</p>
<p>Although <a href="http://www.stata.com/help.cgi?tsvarlist">Stata has powerful lag operators</a> for both time series and panel settings, it is difficult to construct lagged sums of variables across an unbalanced panel.  Suppose you have <img src='http://s.wordpress.com/latex.php?latex=T_i&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='T_i' title='T_i' class='latex' /> observations for <img src='http://s.wordpress.com/latex.php?latex=i%3D1%2C%5Cldots%2CN&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='i=1,\ldots,N' title='i=1,\ldots,N' class='latex' /> individuals.   Each time period you observe some value like investments, hours worked, etc.   The example I discuss below simply counts the number of times an event has occurred up to time <img src='http://s.wordpress.com/latex.php?latex=t&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='t' title='t' class='latex' /> for each observation.  Here an event is &#8220;IPO&#8221; where I need the total number of IPOs prior to $latex  t$.  First, I  construct an indicator for the event and generate a simple date variable that ignores the unbalanced nature of the dataset:</p>
<p><code>gen ipo = (outcome == "IPO")<br />
sort panelid datevar<br />
bysort panelid: gen date = _n<br />
sum date<br />
local total = r(max)<br />
keep panelid date ipo</code></p>
<p>I save this as a temporary dataset for the unfortunate for loop:</p>
<p><code>save temp, replace</code></p>
<p>and reshape for lagged summing:</p>
<p><code>reshape wide ipo, i(panelid) j(date)</code></p>
<p>The following for loop exploits the wide nature of the reshaped data and computes a sum of the IPO variable as of date <img src='http://s.wordpress.com/latex.php?latex=t&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='t' title='t' class='latex' />:</p>
<p><code>forvalues x = 2(1)`total'{<br />
if(`x'==2){<br />
gen total_ipo2 = ipo1<br />
}<br />
else {<br />
local minx = `x'-1<br />
gen total_ipo`x' = total_ipo`minx' + ipo`minx'<br />
}<br />
}</code></p>
<p>Now have to reshape back</p>
<p><code>drop ipo1-ipo`total'<br />
reshape long total_ipo, i(panelid) j(date)<br />
drop if total_ipo == .<br />
sort panelid date</code></p>
<p>The sums in the for loop above generate one too many observations at the end of each observations time series that we need to drop:</p>
<p><code>bysort panelid: gen n = _n<br />
bysort panelid: gen nn = _N<br />
drop if n == nn<br />
drop n nn<br />
keep panelid date total_*<br />
sort panelid date</code></p>
<p>And it is done.  I am sure that there is a more elegant solution&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelewens.com/2009/05/19/create-a-lagged-sum-variable-in-stata/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple Bootstrap Sample in Matlab</title>
		<link>http://michaelewens.com/2009/03/25/simple-bootstrap-sample-in-matlab/</link>
		<comments>http://michaelewens.com/2009/03/25/simple-bootstrap-sample-in-matlab/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 08:39:38 +0000</pubDate>
		<dc:creator>Michael Ewens</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[bootstrap]]></category>
		<category><![CDATA[matlab]]></category>

		<guid isPermaLink="false">http://michaelewens.com/?p=171</guid>
		<description><![CDATA[Let x be your vector of data which has to be bootstrapped. For each instance of the loop write: x = x(floor(rows(x)*rand(rows(x),1))+1,:); % bootstrap observations Now we have a matrix with the same number of rows and columns, but with re-sampled data with replacement. A one line bootstrap! (Modified code from John Cochrane)]]></description>
			<content:encoded><![CDATA[<p>Let x be your vector of data which has to be <a href="http://en.wikipedia.org/wiki/Bootstrapping">bootstrapped</a>. For each instance of the loop write:</p>
<p><code>x = x(floor(rows(x)*rand(rows(x),1))+1,:); % bootstrap observations</code></p>
<p>Now we have a matrix with the same number of rows and columns, but with re-sampled data with replacement. A one line bootstrap! (Modified code from John Cochrane)</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelewens.com/2009/03/25/simple-bootstrap-sample-in-matlab/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using Remote Files in Matlab</title>
		<link>http://michaelewens.com/2009/03/24/using-remote-files-in-matlab/</link>
		<comments>http://michaelewens.com/2009/03/24/using-remote-files-in-matlab/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 08:37:31 +0000</pubDate>
		<dc:creator>Michael Ewens</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[matlab]]></category>
		<category><![CDATA[remote access]]></category>

		<guid isPermaLink="false">http://michaelewens.com/?p=169</guid>
		<description><![CDATA[If you have an FTP server set-up somewhere with ample space and bandwidth, Matlab can store and retrieve its files and data remotely. Just use these simple commands to connect and disconnect: % File to connect to the server where my Matlab/data resides % connect to the db f = ftp('yourdomain.com', 'user', 'password'); % change [...]]]></description>
			<content:encoded><![CDATA[<p>If you have an FTP server set-up somewhere with ample space and bandwidth, Matlab can store and retrieve its files and data remotely. Just use these simple commands to connect and disconnect:</p>
<p><code>% File to connect to the server where my Matlab/data resides</p>
<p>% connect to the db<br />
f = ftp('yourdomain.com', 'user', 'password');</p>
<p>% change the directory<br />
cd(f, 'matlab');</p>
<p>% now change the directory that we want to download the directory<br />
cd '/';</p>
<p>% Download the directory<br />
mget(f, 'remote_dir');</p>
<p>% *****************<br />
% INSERT PROGRAM HERE<br />
% *****************</p>
<p>% when done move a directory here<br />
cd ..<br />
% now move the directory back to the server<br />
mput(f, 'remote_dir');<br />
disp('Files have been put back on the server');</p>
<p>% close the connect<br />
close(f);</code></p>
]]></content:encoded>
			<wfw:commentRss>http://michaelewens.com/2009/03/24/using-remote-files-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>
	</channel>
</rss>

