[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Re: first program
If you are planning to run this program only in one dataset (that uses id as
cross-sectional identifier) you dont need to put it in the syntax. When you
put id in the syntax you are creating a temporary variable called id that
will be use further, for that reason you have to invoke it using `id'
instead of id.
You are not using [if] and [in], putting these in the syntax line just
allows to use them. This means that the users can conditional the result but
your program still needs to apply the restrictions... read marksample to get
a formal uses of [if] and [in].
You have to define a temporary variable count in order to prevent that this
variable already exists in the dataset. Again, you have to invoke it using
`count' instead of count. After keep you will lose information, be careful
Finally, I don't understand what did you mean with "compile". You just load
the program with -do balance- or even more, you can save this program with
the extension .ado into your personal folder and this will be your own
PS: This is my version of your program:
syntax [if] [in]
local ivar: char _dta[iis]
by `ivar': egen `count'=count(`ivar') `if' `in'
keep if `count'==`max'
I dropped rclass, because I don't need to save any value after reducing the
panel. Also, I deleted id of the syntax because you can use char _dta[iis]
that tells you which cross-sectional variable was defined using -tsset-.
Note that local variables as well [if] and [in] are invoked using `'.
----- Original Message -----
I am trying to write my first Stata program and was wondering if someone
could go through it and tell me if it's correct, how I should refer to id
and what rclass means (just copied that).
Another thing, I compiled it once and then wanted to recompile it. How do I
program to balance an unbalanced panel, keep only those individuals with the
program balance, rclass
syntax id [if] [in]
by id: egen count=count(id)
keep if count==max
Department for Work and Pensions
Level 4, The Adelphi
1-11 John Adam St
WC2N 6HT London
020 796 28531
* For searches and help try: