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 |
Nick Cox <njcoxstata@gmail.com> |

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

Subject |
Re: st: How can I loop this? |

Date |
Sat, 4 May 2013 21:32:17 +0100 |

No need to loop. Your question is an FAQ. http://www.stata.com/support/faqs/data-management/replacing-missing-values/ Nick njcoxstata@gmail.com On 4 May 2013 21:23, Adam Guerrero <adamgue@gmail.com> wrote: > 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/ * * 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:*Adam Guerrero <adamgue@gmail.com>

**References**:**st: How can I loop this?***From:*Adam Guerrero <adamgue@gmail.com>

- Prev by Date:
**st: How can I loop this?** - Next by Date:
**Re: st: Time-series operators and -outreg-** - Previous by thread:
**st: How can I loop this?** - Next by thread:
**Re: st: How can I loop this?** - Index(es):