[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Surajit Das" <surajitdas@fastmail.fm> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Fri, 21 May 2004 02:28:45 +0530 |

May be you should go back to the original program which generated the .csv files in the first place and generate the data in plain ascii format. Then you can use a .dct files to read the file in whatever format you want to read it. In stead of keeping the data as _01,001,00003_ _02,02,004_ you can probably keep it as _0100100003_ _02 02 004_ Then you can read the data by an .dct file as follows try.dct dictionary using "my.txt"{ _column(1) str2 x %2s _column(3) str3 y %3s _column(6) str5 z %5s } infile using "try.dct" Best, surajit On Thu, 20 May 2004 16:35:25 +0100, "Nick Cox" <n.j.cox@durham.ac.uk> said: > Try some variation on > > . infile a b str80 c d e using my.csv > > where the "str80" must precede the variable > name and where "80" can be replaced by the > largest number of digits. > > > Nick > n.j.cox@durham.ac.uk > > > -----Original Message----- > > From: owner-statalist@hsphsun2.harvard.edu > > [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of > > Rebecca Kalmus > > Sent: 20 May 2004 16:13 > > To: statalist@hsphsun2.harvard.edu > > Subject: st: RE: RE: RE: inputting string variables in comma-separated > > files > > > > > > That's helpful, thanks. However, that only works if the > > variable has the > > same number of digits for all observations. Suppose one > > observation is > > 001 and another is 0001, both of which are read into Stata as > > 1, and no > > observation has more than four digits for this variable. In that case > > tostring will turn this variable into 0001 for both these > > observations. > > > > Rebecca Kalmus > > > > ********************************************************************* > > > > 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/ > > > > * > * 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/ -- http://www.fastmail.fm - Send your email first class * * 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/

**References**:**st: RE: RE: RE: RE: inputting string variables in comma-separated files***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: Re: -mlogit- does not report all results** - Next by Date:
**st: xtlogit** - Previous by thread:
**st: RE: RE: RE: RE: inputting string variables in comma-separated files** - Next by thread:
**st: RE: Using postfile** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |