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: -set obs- for -tempfile-
From
"Lythgoe, Dan" <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
RE: st: -set obs- for -tempfile-
Date
Tue, 19 Feb 2013 14:59:02 +0000
Thanks for the advice Nick - I can see where I was going wrong now.
Many thanks,
Dan Lythgoe
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: 19 February 2013 13:52
To: [email protected]
Subject: Re: st: -set obs- for -tempfile-
As you say, there are some misunderstandings here.
-tempfile- itself does no more than set up a temporary _name_ for a file that you may (or indeed may not) use later in the same program.
It's like booking a table in a restaurant or seats for a performance.
If I do this
. tempfile foo
. di "`foo'"
C:\DOCUME~1\NJCGEO~1.000\LOCALS~1\Temp\ST_0u000001.tmp
. dir "`foo'"
file not found
Stata has done one (and only one) thing: worked out a name for a file ahead of its use; at that point the file does not even exist.
So, your problems of understanding are quite different
1. -set obs- will not _reduce_ the number of observations in memory.
This is all part of Stata's attitude that it won't destroy data as a side-effect of something else. That's why Stata is complaining; no files are implied in the complaint.
2. You don't need to -set obs- for a file. Indeed that does not even have a meaning as -set obs- refers only to the dataset _in memory_. In order to write 12 observations to a file, write 12 observations to a file; -set- is not needed and does not even apply directly.
3. It also follows that there is no sense in which -set obs- refers back to the original file, which remains exactly as it was (unless you change it, which you would have to do some other way).
There will be a kind of "Yes, of course" when you think it through....
Nick
On Tue, Feb 19, 2013 at 12:27 PM, Lythgoe, Dan <[email protected]> wrote:
> I'm clearly missing something when it comes to -tempfile- and I wonder if you can help. With a data set in memory I want to create a (very small) temporary data set where I can -set obs-, plot a simple graph and then restore the original data. Using a combination of -preserve- and -clear- works fine:
>
> /****START****/
> sysuse auto, clear
>
> preserve
> clear
> set obs 12
> gen x = _n
> gen y = x^2
> line y x
> /****END****/
>
>
> However I had anticipated that using -tempfile- would do the same but clearly -set obs- is not setting the number of observations for the temporary file but for the original file:
>
>
> /****START****/
> sysuse auto, clear
>
> tempfile temp
> set obs 12
> gen x = _n
> gen y = x^2
> line y x
> /****END****/
>
> Returns the error:
>
> obs must be between 74 and 2147483646
> r(198);
>
*
* 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/