Bookmark and Share

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: Reading a variable from a spreadsheet and saving it as a macro


From   Miles Grogger <[email protected]>
To   [email protected]
Subject   Re: st: Reading a variable from a spreadsheet and saving it as a macro
Date   Tue, 6 Aug 2013 11:11:26 -0500

Thanks Sergiy,

I was thinking the exact same thing when the error message showed up.
It will run this code through line 12 (display `shnames') and then
crash stating "chp not found".

local indir "/Users/milesgrogger/Dropbox/PAC_Facilities/FullChapters/1995-2011"
local outdir "/Users/milesgrogger/Desktop"
cd `outdir'
import excel chapters.xlsx, firstrow
reshape long state, i(stcode) j(year)
local fnames "state[1] state[2] state[3]"
clear
import excel sheets.xlsx, firstrow
reshape long chp, i(stcode) j(year)
local shnames "chp[1] chp[2] chp[3]"
clear
display `shnames'
display `fnames'

The same thing happens if I substitute "clear" for "drop _all". My
only hypothesis thus far for the error is that stata is reading
`fnames' as having the contents "state[1] state[2] state[3]", and
`shnames' with it's version in turn, rather than reading the contents
of "state[1...2....3].

Thanks in advance for any additional help,
Miles

On Tue, Aug 6, 2013 at 10:42 AM, Sergiy Radyakin <[email protected]> wrote:
> On Tue, Aug 6, 2013 at 11:17 AM, Miles Grogger <[email protected]> wrote:
>> Hi all,
>>
>
>> but when I cleared the dataset to make room for the next workbook, the
>> macros were cleared too.
>
> This should not be happening as the following script demonstrates, the
> locals survive clearing the dataset:
>
> version 12.0
> sysuse auto, clear
> local a="test"
> clear all
> assert `"`a'"'=="test"
>
> Perhaps something else is going on?
>
> Also note that in Stata 13 there are new commands to interact with
> Excel. If you have Stata 13, this is what you probably need:
> http://www.stata.com/manuals13/m-5xl.pdf
>
> With that you should be able to have multiple Excel spreadsheets open
> simultaneously and have random access to individual cells.
>
> Best, Sergiy Radyakin
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index