Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: shifting values one period ahead


From   Eric Booth <ebooth@ppri.tamu.edu>
To   "<statalist@hsphsun2.harvard.edu>" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: shifting values one period ahead
Date   Wed, 22 Sep 2010 23:19:23 +0000

<>


bys id : g newvar1 = var1[_n-1]
replace newvar = 0 if mi(newvar1)




EAB

__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu


On Sep 22, 2010, at 6:13 PM, asb stata wrote:

> I am facing a tricky coding issue that involves creating 'newvar1'
> from 'var1' given 'id' and 'start'. The variable 'newvar1' is obtained
> by shifting 'var1' one period ahead within each 'id'.
> 
> id	start	var1	newvar1
> 
> 1	1	1	0
> 1	0	1	1
> 1	0	0	1
> 1	0	0	0
> 
> 2	0	0	0
> 2	0	0	0
> 2	1	1	0
> 2	0	0	1
> 2	0	1	0
> 
> 3	0	0	0
> 3	0	0	0
> 3	1	1	0
> 3	0	1	1
> 3	0	1	1
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index