Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: RE: inputting string variables in comma-separated files


From   Joseph Coveney <jcoveney@bigplanet.com>
To   Statalist <statalist@hsphsun2.harvard.edu>
Subject   Re: st: RE: RE: inputting string variables in comma-separated files
Date   Wed, 19 May 2004 23:37:22 +0900

I think what Nick was trying to get at is that you can recreate your lost 
leading zeroes by using the -format()- option in -tostring- as illustrated 
below.

Joseph Coveney

--------------------------------------------------------------------------------

. clear

. set obs 5
obs was 0, now 5

. generate int x = 10^(_n - 1)  // <- original comma-separated values

. tostring x, generate(sx) format(%05.0f)  // note the format--leading zeroes
sx generated as str5

. clist, noobs

       x         sx
       1      00001
      10      00010
     100      00100
    1000      01000
   10000      10000

--------------------------------------------------------------------------------

From: Rebecca Kalmus wrote:

Once I've read the comma-separated file into Stata, Stata has already read
the variable as numeric.  The leading zeros are already gone, so
converting the variable to string using tostring doesn't help.

In the past I've gotten around this problem by converting the
comma-separated file to Stata format using Stat/transfer, with which I can
specify that the variable should be read as string.  However, it seems
like there should be a more straightforward solution.

Rebecca Kalmus

> >From   "Nick Cox" <n.j.cox@durham.ac.uk>
> To   <statalist@hsphsun2.harvard.edu>
> Subject   st: RE: inputting string variables in comma-separated files
> Date   Tue, 18 May 2004 19:46:19 +0100
>
> A good bet in this circumstance is to make
> it a string variable again using -tostring-.
> Make sure you specify a format which produces
> leading zeros.
>
> Nick
> n.j.cox@durham.ac.uk
>

--------------------------------------------------------------------------------


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index