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: How to generate a variable made up of sections of other variables
From
Matthew Mroczek <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: How to generate a variable made up of sections of other variables
Date
Thu, 5 May 2011 09:34:02 +0000
Hi All,
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.
Cheers,
Mateusz Mroczek
Queensland University of Technology
*
* 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/