Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Adam Guerrero <adamgue@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: How can I loop this? |

Date |
Sat, 4 May 2013 16:23:34 -0400 |

Hi Stata Users, I have an unbalanced panel comprised of student years which can be reshaped into student terms (six years, three terms per year, providing a maximum 18 observations per student). One of the variables included in the data is a student's major area of specialization - major1. For some students this variable is defined at the start of their educations, missing for a few years, then defined again. After consulting with the registrar at the institution under analysis the following code was used to fill in the gaps by id: replace major1=major1[_n+1] if major1=="" & major1[_n+1]!="" & _n!=_N by id: replace major1=major1[_n+1] if major1=="" & major1[_n+1]!="" & _n!=_N by id: replace major1=major1[_n+1] if major1=="" & major1[_n+1]!="" & _n!=_N by id: replace major1=major1[_n+1] if major1=="" & major1[_n+1]!="" & _n!=_N by id: replace major1=major1[_n+1] if major1=="" & major1[_n+1]!="" & _n!=_N In other words, I had to type the same line of code over and over until all of the values were replaced. My question is whether there is a more efficient way to do this? I'm relatively new to Stata, so any advice would be very much appreciated. Adam Antonio * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: How can I loop this?***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**Re: st: Non-linear panel model estimation in Stata** - Next by Date:
**Re: st: How can I loop this?** - Previous by thread:
**st: How to calculate intercept and slope of ROC curve - STATA 12.1** - Next by thread:
**Re: st: How can I loop this?** - Index(es):