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: shifting values one period ahead


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
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
[email protected]


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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index