[email protected]
>
> Thanks Nick and David for the help.
>
> David, I mean the exact correspondence: var1 for a, var2 for b, etc.
>
> If a variable is absent, it would be preferable not to
> create it, since the
> program is huge.
> For example, if a does not exist or contains no
> observation, thus, it would be
> preferable not to create var1.
> Even though we create new variables with missing values,
> they would be
> irrelevant for my regressions.
>
> For var5, if at least one of the variables exists, then I
> want to use it to
> create var5. If not, it will not be created.
>
> Nick, all the code is there. My intend is simple.
> Let me rewrite all my program below: my dependent variable
> is depvar (which is
> common to all files).
>
> local varlist1 "a b c d e f g h"
> foreach x of local varlist1 {
> capture confirm var `x'
> if _rc==0 {
> capture assert mi(`x')
> if _rc==0 {
> drop `x'
> }
> else {
> g var1=a
> g var2=b
> g var3=c
> g var4=d
> g var5=.
> replace var5=1 if e==1| f==1| g==1| h==1
> }
> }
> regress depvar var1 var2 var3 var4 var5 /*if one of
> them exists*/
>
> The first suggestion of Nick seems good, but since I have a
> lot of variables to
> create, it will be very difficult to rewrite the code for
> each of them.
> I will try his second suggestion.
You are correct. My first comment does not
apply, as I misread your code. But perhaps you now have
the ingredients of a solution from various suggestions.
Nick
[email protected]
*
* 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/