Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 73268

How to use IF condition before running a inner loop of FORV

$
0
0
I am struggling with imposing if condition on a inner loop. Consider the following example where a user can input five dependent variables with names S1 S2 S3 S4 S5 or S1H1 S1H2 S1H3 S1H4 S1H5,
:
    local LHS : word 1 of `varlist'
    local S = substr("`LHS'",1,1)
    local H = substr("`LHS'",3,1)
    local NF: word count `varlist'


forv s=1/`NF'{
  *IF condition is required here
      forv h=1/`NF'{
            reg `S'`s'`H'`h' `flist'
      }
}
let say that the user inputs the first series of dependent variables i.e. S1 S2 S3 S4 S5, then I just need the higher loop i.e.
:
 forv s=1/`NF'{
However, if the user inputs the second series i.e., S1H1 S1H2 S1H3 S1H4 S1H5, then I need both the outer and inner loops. i.e.
:
forv s=1/`NF'{
      forv h=1/`NF'{
            reg `S'`s'`H'`h' `flist'
      }
}

Viewing all articles
Browse latest Browse all 73268

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>