Bookmark and Share

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: identifying change in cell values


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: identifying change in cell values
Date   Fri, 15 Mar 2013 11:52:03 +0000

The -tag()- function [NB] of the -egen- command does not have the role
of detecting _new_ values. Its role is to tag or flag precisely one of
any group of observations that is identical on the variables
specified.

If  you look at the source code with

. viewsource _gtag.ado

you can see that in practice the function finds the first such
occurrence. That was originally (Cox 1999), and is now, just an
arbitrary choice. That's by the way.

STB-50  dm70  . . . . . . . . . . . . . . . . Extensions to generate, extended
        (help egenodd if installed) . . . . . . . . . . . . . . . .  N. J. Cox
        7/99    pp.9--17; STB Reprints Vol 9, pp.34--45
        24 additional egen functions presented; includes various string,
        data management, and statistical functions;
        many of the egen functions added to Stata 7

I suspect from the previous thread that Adeel opened

http://www.stata.com/statalist/archive/2013-03/msg00424.html

that his interest in panel data. If so, the principles of identifying
spells apply here. In

http://www.stata.com/statalist/archive/2013-03/msg00446.html

Rebecca Pope directed Adeel to -tsspell- (SSC). The corresponding
principles of identifying spells were discussed in

SJ-7-2  dm0029  . . . . . . . . . . . . . . Speaking Stata: Identifying spells
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q2/07   SJ 7(2):249--265                                 (no commands)
        shows how to handle spells with complete control over
        spell specification

which is accessible in .pdf form at

http://www.stata-journal.com/article.html?article=dm0029

Note that the article does not mention -tsspell-. The explanation is
mundane. I wrote -tsspell- (the help file flags people who contributed
to the project, most notably Richard Goldstein) and then later decided
to write about the ideas. The original intention was to follow the
ideas part with a section on -tsspell- that explained one canned
implementation, but the paper was already long enough before I ever
got to writing that section.

I doubt that there will ever be a sequel on -tsspell-, but I should
add a reference to the 2007 paper to the help of -tsspell-.

All that aside, a basic way to identify a changed value in panel data is just

bysort panelid (time) : gen different = thisvar != thisvar[_n-1]

with the proviso that a missing value for -thisvar[1]- will not be
flagged as different from -thisvar[0]-, so

bysort panelid (time) : gen different = thisvar != thisvar[_n-1] | (_n == 1)

might be preferred. Again, for a much fuller discussion, please see my
2007 paper. It is full of little things that are elementary once you
have worked them out.

Nick

On Fri, Mar 15, 2013 at 1:53 AM, Adeel Yousaf
<[email protected]> wrote:

> I applied the  'tag' command that is detecting new values, how can i
> detect change in the value of 'coded' either repeating or new.
>
>  egen tagcoded = tag( coded)
>
>
> coded   tagcoded
> 24      1
> 24      0
> 28      1
> 27      1
> 27      0
> 27      0
> 27      0
> 27      0
> 28      0
> 22      1
> 22      0
> 24      0
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index