Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: creating a text file with a specific format


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: creating a text file with a specific format
Date   Mon, 6 Feb 2012 18:50:17 +0000

By social security numbers I guess you mean as used in the United States, which I understand to mean up to 9 numeric digits. 

-tostring- is perfectly capable of insisting on leading zeros for those and other numbers. 

. gen long SSN = 87654321

. l SSN in 1

     +----------+
     |      SSN |
     |----------|
  1. | 87654321 |
     +----------+

. tostring SSN, gen(mySSN) format(%09.0f)
mySSC generated as str9

. l *SSN in 1

     +----------------------+
     |      SSN       mySSN |
     |----------------------|
  1. | 87654321   087654321 |
     +----------------------+

You just need to specify an appropriate format. 

Nick 
[email protected] 

Michael Eisenberg

Thanks Nick.  It was a general question.

One problem with converting to a string that I have is that when I
attempt to convert a social security number or any other numbers into
a string, it truncates any leading zero's.

tostring ssn, gen(ssnstr)

On Mon, Feb 6, 2012 at 8:38 AM, Nick Cox <[email protected]> wrote:
> Is this a general question, or a specific question about Austin Nichols' -outfixt-?
>
> In general: Convert to string first.
>
> Nick
> [email protected]
>
> Michael Eisenberg
>
> Thanks so much.
>
> Is there a way to replace missing values with no characters rather than a "." ?
>
>
>
> On Tue, Jan 17, 2012 at 7:05 AM, Austin Nichols <[email protected]> wrote:
>> Michael Eisenberg <[email protected]>:
>> replace lastname=substr(lastname,1,20)
>> *etc, then:
>> ssc install outfixt
>>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index