Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
6
Task/Loops-Nested/Stata/loops-nested-1.stata
Normal file
6
Task/Loops-Nested/Stata/loops-nested-1.stata
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
matrix a=J(20,20,0)
|
||||
forv i=1/20 {
|
||||
forv j=1/20 {
|
||||
matrix a[`i',`j']=runiformint(1,20)
|
||||
}
|
||||
}
|
||||
16
Task/Loops-Nested/Stata/loops-nested-2.stata
Normal file
16
Task/Loops-Nested/Stata/loops-nested-2.stata
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
local q 0
|
||||
forv i=1/20 {
|
||||
forv j=1/20 {
|
||||
display "check `i',`j'"
|
||||
if el("a",`i',`j')==20 {
|
||||
display "found at `i',`j'"
|
||||
local q 1
|
||||
continue, break
|
||||
}
|
||||
}
|
||||
|
||||
if `q' continue, break
|
||||
}
|
||||
if !`q' {
|
||||
display "not found"
|
||||
}
|
||||
17
Task/Loops-Nested/Stata/loops-nested-3.stata
Normal file
17
Task/Loops-Nested/Stata/loops-nested-3.stata
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
local q 0
|
||||
local i=1
|
||||
while !`q' & `i'<=20 {
|
||||
local j=1
|
||||
while !`q' & `j'<=20 {
|
||||
display "check `i',`j'"
|
||||
if el("a",`i',`j')==20 {
|
||||
display "found at `i',`j'"
|
||||
local q 1
|
||||
}
|
||||
local ++j
|
||||
}
|
||||
local ++i
|
||||
}
|
||||
if !`q' {
|
||||
display "not found"
|
||||
}
|
||||
18
Task/Loops-Nested/Stata/loops-nested-4.stata
Normal file
18
Task/Loops-Nested/Stata/loops-nested-4.stata
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
capture {
|
||||
forv i=1/20 {
|
||||
forv j=1/20 {
|
||||
display "check `i',`j'"
|
||||
if el("a",`i',`j')==20 {
|
||||
display "found at `i',`j'"
|
||||
exit -1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if _rc==-1 {
|
||||
// value was found
|
||||
}
|
||||
else if _rc==0 {
|
||||
display "not found"
|
||||
}
|
||||
else exit _rc
|
||||
52
Task/Loops-Nested/Stata/loops-nested-5.stata
Normal file
52
Task/Loops-Nested/Stata/loops-nested-5.stata
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
function findval1(a,x,i0,j0) {
|
||||
n=rows(a)
|
||||
p=cols(a)
|
||||
for (i=1; i<=n; i++) {
|
||||
for (j=1; j<=p; j++) {
|
||||
if (a[i,j]==x) {
|
||||
i0=i
|
||||
j0=j
|
||||
return(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
return(0)
|
||||
}
|
||||
|
||||
function findval2(a,x,i0,j0) {
|
||||
n=rows(a)
|
||||
p=cols(a)
|
||||
q=0
|
||||
for (i=1; i<=n; i++) {
|
||||
for (j=1; j<=p; j++) {
|
||||
if (a[i,j]==x) {
|
||||
i0=i
|
||||
j0=j
|
||||
q=1
|
||||
goto END
|
||||
}
|
||||
}
|
||||
}
|
||||
END:
|
||||
return(q)
|
||||
}
|
||||
|
||||
function findval3(a,x,i0,j0) {
|
||||
n=rows(a)
|
||||
p=cols(a)
|
||||
q=0
|
||||
for (i=1; i<=n; i++) {
|
||||
for (j=1; j<=p; j++) {
|
||||
if (a[i,j]==x) {
|
||||
i0=i
|
||||
j0=j
|
||||
q=1
|
||||
break
|
||||
}
|
||||
}
|
||||
if (q) {
|
||||
break
|
||||
}
|
||||
}
|
||||
return(q)
|
||||
}
|
||||
4
Task/Loops-Nested/Stata/loops-nested-6.stata
Normal file
4
Task/Loops-Nested/Stata/loops-nested-6.stata
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
a=st_matrix("a")
|
||||
findval1(a,20,i=.,j=.)
|
||||
findval2(a,20,i=.,j=.)
|
||||
findval3(a,20,i=.,j=.)
|
||||
Loading…
Add table
Add a link
Reference in a new issue