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]

From |
Nick Cox <n.j.cox@durham.ac.uk> |

To |
"'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |

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 n.j.cox@durham.ac.uk 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/

**References**:**st: How to generate a variable made up of sections of other variables***From:*Matthew Mroczek <matthew.mroczek@connect.qut.edu.au>

- Prev by Date:
**st: RE: 5 year panels** - Next by Date:
**st: How do I use a local within a global?** - Previous by thread:
**st: How to generate a variable made up of sections of other variables** - Next by thread:
**st: How do I use a local within a global?** - Index(es):