Statalist


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

Re: st: importing changes variable to numeric but want string variable


From   Richard Goldstein <richgold@ix.netcom.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: importing changes variable to numeric but want string variable
Date   Fri, 08 Feb 2008 14:33:50 -0500

First, you don't tell us how you imported the file -- if you used -infile- you can tell Stata that the variable should be a string; if you used a third party program (e.g., StatTransfer) you can also tell the program that you want a particular variable to be a string

Second, you can always make this into a string variable (use -tostring- for example) and then pad with leading 0's (e.g., -replace var="00000" if length(var)==1)

Rich

Ms. Marilyn Ibarra wrote:

I have a text file with data that looks like this:

us_id firm_name
000007 x
012231 y
100210 z
345211 w

I imported the txt file. When I do this I get data that looks like this:

us_id firm_name
7 x
12231 y
100210 z
345211 w

As you can see the zeros at the beginning of the first two observations of us_id are dropped. How do I prevent this from happening because I need it in the format of the original txt file. I need it to be a string variable and not numeric.
Any ideas? Thanks in advance,

Marilyn.
*
*   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