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]

st: RE: How to generate a variable made up of sections of other variables‏


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: How to generate a variable made up of sections of other variables‏
Date   Thu, 5 May 2011 10:50:32 +0100

Just focusing on the second sentence, that is 

replace y = x[_n-40] in 60/70 

I don't see that a loop is needed for that. The point is that subscripting can be based on expressions. 

There is no way that -in- conditions can appear before the = exp in a -replace- statement. 

Nick 
[email protected] 

Matthew Mroczek

I am using Stata/SE 11.2 for Windows (64-bit x86-64) Born 30 Mar 2011 and have been trying to create a variable made up of specific sections of a number of other variables. So essentially I would like to replace eg the 60-70th values in my variable with the 20-30th values of another. Also if it complicated matters id like to work in a loop so something along the lines of this

forvalues c  = 1(1)5{
forvalues n = 1(1)5{
forvalues x = 1(1)5 {

sum variable
gen `c'`n'`x' = r(sum)
}

quietly gen p`c'`n' =  p`c'`n'1 in 1
quietly replace p`c'`n' =  p`c'`n'2 in 2
quietly replace p`c'`n' =  p`c'`n'3 in 3
quietly replace p`c'`n' =  p`c'`n'4 in 4
quietly replace p`c'`n' =  p`c'`n'5 in 5

}

quietly gen p`c' =  pds`c'1 in 1/5
quietly replace p`c' in 6/10 =  p`c'2 in 1/5
quietly replace p`c' in 11/15 =  p`c'3 in 1/5
quietly replace p`c' in 16/20 =  p`c'4 in 1/5
quietly replace p`c' in 21/25 =  p`c'5 in 1/5

}

So if anyone could point me in the right direction I'd be very grateful.

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