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: loops - beginner's question


From   Maik Herman <[email protected]>
To   [email protected]
Subject   st: loops - beginner's question
Date   Mon, 1 Nov 2010 14:21:04 +0100

Hello Statalist,

I new to Stata and have a  rather simple question which nevertheless
breaks my nerves today.

I have a panel dataset of firm directors. The dataset is a result of
two sets of data. The problem is, that one dataset uses a different
director identifier than the second. However, some some overlap does
exist. I would like to create a loop which replaces the missing
identifier with the once used in the year before. The loop should
check if the idendifier is missing and if so check if the firm
identifier is identical to last year. I was usind the following code:

sort firm_id year
gen temp_id=dir_id if dir_id!=.
by cusip: replace temp_id=dir_id[_n-1] if firm_id==firm_id[_n-1] &
year==year[_n-1]+1

The code only replace the first observation but I have more than one
directors in each year. I have experimenting with the following code,
which obviously does not do the job.

Can somebody please help or direct me a bit?

while condition on `local’ true {
local i=1
while `i' =. {
 if firm_id=firm_id in year=year-1
replace `i'= dir_id in year=year-1
local i=`i'+1
}

Thanks in advance,

Maik

*
*   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/


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