I am facing problems using the "if" statement (not the "if" qualifier) because the expression in the "if" statement has a variable. Hence, the commands are being executed taking only the first observation of the variable. What is the way to execute the commands for all the observations? I give a details of a prototype (simplified) problem below.
I have two variables x and y. Each can take values 1 or 2. And I have four more variables p11, p12, p21 and p22. I want to go down each observation of x, compare it to y and if they are equal then make p`x'`y'=100, otherwise make p`x'`y'=10.
To do the above task, I write the following program:
++++++++++++++++++++++++++++++++++++++
capture program drop rpc
program define rpc
version 8.0
args size alive
if `size'==`alive' {
replace p`size'`alive'=100
}
else {
replace p`size'`alive'=10
}
end
++++++++++++++++++++++++++++++++++++
I run this program and then run the following do-file:
+++++++++++++++++++++++++++++++++++
set more 1
version 8.0
local i 1
while `i' <=2 {
local j 2
while `j' <= `i' {
gen p`i'`j'=0
local j = `j' + 1
}
local i = `i' + 1
}
rpc x y
+++++++++++++++++++++++++++++++++++++
My problem is that I cannot get the program to go through each observation on x and y. It takes the first observation of x and y and stops there. It does not move to the next observation.
Any suggestions on how to tackle this issue will be greatly appreciated.
Deepankar
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/