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: Excel and numbers treated as strings
From
Rudy Hover <[email protected]>
To
[email protected]
Subject
Re: st: Excel and numbers treated as strings
Date
Wed, 9 May 2012 21:36:48 +0200
I would change the numeric variables to string variables before exporting, i.e. use the tostring command.
Then it is easy to export to Excel.
On May 9, 2012, at 9:24 PM, Douglas Levy wrote:
> Is there a way to export a file from Stata such that Excel or Access
> would treat a numeric variable as a string? I am processing data in
> Stata to be used in a mail merge in Excel or Access. The file I want
> to export has ZIP (postal) codes in it that I need treated as a string
> variable to preserve any leading zeroes.
>
> If Excel (or Access) does a "dumb" import of a .csv or .txt file (that
> is, Excel is given no information on the formats of the variables
> being imported and has to guess), it will ignore leading zeroes and
> treat all number variables as numeric. I want to automate my processes
> as much as possible. My thinking is it will be simpler to automate a
> smart export from Stata than to automate a smart import from Excel.
>
> Is there a trick to exporting data from Stata that will allow Excel
> (or Access) to automatically recognize leading zeroes without being
> told to do so? Perhaps by putting quotation marks surrounding the
> numeric strings before export?
>
> Does it require Stata 12 (which can output Excel files)? Would it even
> work in Stata 12 (can Stata specify that a variable in an outputted
> Excel file is a string)?
>
> Thanks for any advice.
> Best,
> Doug
> *
> * 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/
*
* 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/