Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: adding variables to a new data file


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: adding variables to a new data file
Date   Wed, 13 Feb 2013 09:23:38 +0000

I am not much clearer on what you are trying to do exactly and what
problems there are (other than the problem with a macro button).

It would help to see

1. Examples of precise code you are using.

2. How exactly the length limit of 244 on string variables (not
strings in general) is biting. As you can't have string variables
longer than 244, you can't export them. Presumably you mean something
else, but what is it? It's just possible that David is being bitten by
the limitation discussed in

SJ-8-4  pr0045  . . . . . . . . Stata tip 70: Beware the evaluating equal sign
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q4/08   SJ 8(4):586--587                                 (no commands)
        tip explaining the pitfall of losing content in a macro
        because of limits on the length of string expressions
http://www.stata-journal.com/article.html?article=pr0045

which is easily soluble.

3. What is the "limit on the number of variables that can be exported
at one time"? Which command is this?

On the general picture, it seems that users collectively use Stata in
combination with just about everything else imaginable, and then some,
so the support needs are indefinite. But StataCorp is actively
extending Excel support -- witness -import excel- and -export excel-.

I suspect David will be better off showing some datasets to Stata
technical support and describing what he wants to do. That would
clarify whether there is a solution at present or he needs new
features to be added.

Nick

On Wed, Feb 13, 2013 at 3:39 AM, David Epstein
<david.l.epstein@gmail.com> wrote:
> The larger problem is that I'm trying to get a lot of variable out of
> Stata to Excel. I've posted previously about a bug in the Excel parser
> that won't allow you to export to a file that has a macro button, so
> that's one issue.
>
> And I've tried to just list the variables I want to export, by
> constructing a local macro called varlist. But then I run into Stata's
> limit of 244 characters for a string, so I can't do it that way. Oh,
> and when I try to export the variables all at one time to the Excel
> sheet, I run into a limit on the number of variables that can be
> exported at one time, so I have to do it in shifts, which costs me a
> lot in export time.
>
> So I've run into a number of frustrations trying to do what should be
> a simple task. In general, Stata might make a little more effort to
> make it easy for the program to interact with other external programs.
>
> On Tue, Feb 12, 2013 at 5:37 PM, Nick Cox <njcoxstata@gmail.com> wrote:
>> My point is the same. Just to add that there's a convenience command
>> on SSC, -savesome-.
>>
>> Nick
>>
>> On Tue, Feb 12, 2013 at 10:31 PM, Steve Nakoneshny <scnakone@ucalgary.ca> wrote:
>>
>>> It isn't clear to me why you would need a loop in the first place to identify your variables of interest. Is the size of your dataset a limiting factor due to your version of Stata? Can you not simply keep a running tally of the variables you want to keep and export them en masse?  Perhaps through the judicious use of a do file?
>>
>> On 2013-02-12, at 3:21 PM, David Epstein wrote:
>>
>>>> This must be a really easy question to answer, but I'm feeling
>>>> stumped. I have a data set with a large number of variables in it. I
>>>> want to create a new data set with a subset of those variables, with
>>>> the exact variables to be exported being read off a loop a few
>>>> variables at a time.
>>>>
>>>> So for instance I first want to export the key identifying variable,
>>>> which in my case is date. So I will:
>>>>
>>>> preserve
>>>> keep date
>>>> save temp, replace
>>>> restore
>>>>
>>>> Then I'll loop through my loop once and get the names of five
>>>> variables I want to add to temp, call them v1 v2 v3 v4 v5. The next
>>>> time through, I'll get variables v6 through v10, and so on until I've
>>>> added, say 50 variables to temp.
>>>>
>>>> My question is, what do my loops look like? Am I merging each time
>>>> through? Keeping, say, date v1 v2 v3 v4 v5, merging, then restoring? I
>>>> could, but that seems like it could take a while to keep preserving
>>>> and restoring all the time. Plus, I keep having to save the temp file
>>>> and then switch back to the master data set. Isn't there a command
>>>> that says "take these variables from my current data set and add them
>>>> to another data set?"

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index