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: How can I loop this?


From   Adam Guerrero <[email protected]>
To   [email protected]
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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index