[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: check if variable is constant within id
I am pleased to hear that you don't want
a program to do this.
First without missings,
bysort id (var1) : assert var1 == var1[_N]
checks that values of var1 are constant
Second with missings, we need to set missings
on one side:
gen byte ismiss = missing(var1)
bysort ismiss id (var) : assert var1 == var1[_N]
That's two lines. Perhaps someone can shorten it.
But the solutions here can be worked out from
this FAQ, which says more that I won't repeat here:
How do I list observations in a group that differ on a variable?
My suggestion to you is to scan the FAQs before
> I'm looking for an easy way to check if all the observations for a
> particular variable (say var1) within id (a subject identifying
> variable) are constant a) for the case where missings can be excluded,
> and b) for the case where missings cannot be excluded. The best answer
> would be a one-liner, with a short display. I don't want a
> program to do
* For searches and help try: