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]
Re: st: How can I loop this?
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
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
[email protected]
On 4 May 2013 21:23, Adam Guerrero <[email protected]> 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/