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: Create variable as a copy of a dynamically calculated second variable


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: Create variable as a copy of a dynamically calculated second variable
Date   Thu, 09 Sep 2010 12:14:47 -0400

How about?

 gen NewVar=.
 forv y=2000/2010 {
 	replace NewVar=Value`y' if FirstYear==`y'
 }


hth,
Jeph
	

On 9/9/2010 5:32 AM, Wiemann, Markus wrote:
Hi everyone,

I am not sure whether the following is possible in Stata and, if yes,
how to address the problem.

I want to assign a new variable a value that is already stored in a
second variable. The problem is that I need a value of a variable that
is calculated dynamically. Let me explain it in a short example: Assume
I have the following variables:

FirstYear
Value2000
Value2001
Value2002
...
Value2010


What I need is something like
. gen NewVariable = Value[String(FirstYear + 1)]
that would read the value out of Value2006 if FirstYear had the value
2005. Is this possible in Stata? Would I need to write a macro for that?



Thanks and best regards
Markus



*
*   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