Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[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 <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
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 
n.j.cox@durham.ac.uk 

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 <n.j.cox@durham.ac.uk> wrote:
> Is this a general question, or a specific question about Austin Nichols' -outfixt-?
>
> In general: Convert to string first.
>
> Nick
> n.j.cox@durham.ac.uk
>
> 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 <austinnichols@gmail.com> wrote:
>> Michael Eisenberg <meisenberg713@gmail.com>:
>> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index