<?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; leading zeroes</title>
	<atom:link href="http://enoriver.net/index.php/tag/leading-zeroes/feed/" rel="self" type="application/rss+xml" />
	<link>http://enoriver.net</link>
	<description>computing for fun and profit</description>
	<lastBuildDate>Fri, 13 Aug 2010 20:42:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Leading zeroes</title>
		<link>http://enoriver.net/index.php/2008/11/11/leading-zeroes/</link>
		<comments>http://enoriver.net/index.php/2008/11/11/leading-zeroes/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 20:23:56 +0000</pubDate>
		<dc:creator>Gabi Huiber</dc:creator>
				<category><![CDATA[Stata]]></category>
		<category><![CDATA[date and time functions]]></category>
		<category><![CDATA[leading zeroes]]></category>

		<guid isPermaLink="false">http://enoriver.net/?p=287</guid>
		<description><![CDATA[I am working on a project where occasionally I need to keep time using dates in the format YYYYMMDD. I sometimes also need to move back and forth between these dates and numeric year, month, day, which requires things like turning the numeric month 1 into the string "01". The general syntax for turning numbers [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on a project where occasionally I need to keep time using dates in the format YYYYMMDD. I sometimes also need to move back and forth between these dates and numeric year, month, day, which requires things like turning the numeric month 1 into the string "01".</p>
<p>The general syntax for turning numbers to strings with leading zeroes is easy enough. Here's an example with social security numbers:</p>
<p><code>gen str9 ssn_string=string(ssn_numeric, "%09.0f")</code></p>
<p>For dates, this syntax would translate like so:</p>
<p><code><br />
local when `c(current_date)'<br />
display "`when'"<br />
</code><code><br />
local pieces "year month day"<br />
local length "4 2 2"<br />
forvalues i=1/3 {<br />
local w: word `i' of `pieces'<br />
local k: word `i' of `length'<br />
local `w'=string(`w'(date("`when'","DMY")),"%0`k'.0f")<br />
}<br />
local when="`year'`month'`day'"<br />
display "`when'"<br />
</code></p>
<p>Of course, you don't need to use the string type. Getting back to Stata's original social security number example, if you want leading zeroes but you also want to keep the numeric type, you can simply say</p>
<p><code>format ssn %09.0f</code></p>
<p>See the Stata help for <code>format</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://enoriver.net/index.php/2008/11/11/leading-zeroes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
