Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Alan Riley <ariley@stata.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: [Stata 12] Issue with -export excel- |
Date | Wed, 27 Jul 2011 18:06:42 -0500 |
Eric Booth (ebooth@ppri.tamu.edu) asked some questions about Stata 12. Eric's first question was about an error he received after exporting a dataset to .xlsx format with -export excel-. He answered his own question when he found that one of his string variables contained a binary character in one of its values. Excel cannot read a .xlsx file which contains a binary character in a string value. Printable extended ASCII characters are supported. Eric's third question regarding shifting blocks of code in the Do-file Editor in Stata for Mac was answered here: http://www.stata.com/statalist/archive/2011-07/msg00963.html Eric's second question involved an error he received when using an -if- statement without curly braces { } to indicate the code that should be executed when the -if- condition is true. In addition, the code he wanted to execute used an '!' to shell out to the operating system. When Eric coded foreach file in input dta { if "`c(os)'" == "MacOSX" { !open "from`file'.xlsx" } } his code worked as expected. But, when he coded foreach file in input dta { if "`c(os)'" == "MacOSX" !open "from`file'.xlsx" } he received an error. Eric thought this error was new to Stata 12 and that Stata 11 ran such code fine. Both Stata 11 and Stata 12 can execute code that looks like if some_expression do_this_if_some_expression_is_true And, both Stata 11 and Stata 12 can execute code that looks like if some_expression { do_this_if_some_expression_is_true } However, if the single-line case, if the code to be executed when the expression is true begins with an exclamation point (!) to shell out to the operating system, both Stata 11 and Stata 12 will error out: if some_expression !do_this_by_shelling_out Stata's expression parser is interpreting the '!' as part of the expression even though it doesn't affect evaluation of the expression. Thus, when shelling out to the operating system in an -if- condition, Eric should always code if some_expression { !do_this_by_shelling_out } -- Alan ariley@stata.com * * 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/