Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: -1 observations deleted

From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: Re: -1 observations deleted
Date   Wed, 14 Aug 2002 15:00:16 +0100

"Lee Chuntao" <[email protected]>

>       I need to connect a lot of files together by using the command
> using". Those files all contain the same six variables, but
> numbers of observations. Some contain 0 observations. I also need to
> some observations in some conditions. For the zero-observation
files, surely
> i deleted zero observation by using "drop if condition", but stata
> "-1 observations deleted". This is something easily be
misunderstood. My
> question is, why stata not report "0 observation deleted".

I agree that's a puzzling message.

But I don't understand what the real problem is.

If you don't know that a file contains 0 observations
you can check ahead of reading it in:

qui d using file
if r(N) > 0 {
	append using file

That is, a -describe- without reading in the file
will leave behind a count of the number of observations,
which you can then use to avoid reading in an empty data set.

>       another question is also related to zero-observation files.
there is a
> variable named date, and i need to sort obs. decendingly. If i use
> "gsort -date", there is an error, but if i use the following
commands, it
> works well:

>                gen n_date = -date
>                gsort n_date
>                drop n_date

> this seems rather  stupid since we have a command "gsort -varname"
> can stata co. upgrade the gsort command?

Let me get this straight. You are reporting a bug: you
cannot use -gsort- to reverse sort a file with 0
observations. OK. You could get round this by
writing your own copy of -gsort-, say -gsort2-,
which would be the same as -gsort- except that
early on you have these lines

qui count
if r(N) < 2 {
	exit 0

which will throw you out gently without
changing your data set (the way I see it,
any data set with <2 observations is invariant under any kind of
-sort-, so the -sort- is redundant).

If the problem is that you are doing this
in an automated way, and you are not
clear in advance which files have
zero observations, then my answer is as above.

[email protected]

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index