Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: Re: using categorical and continuous variables foreach loop for univaraite analysis

 From Michael Stewart To statalist Subject Re: st: Re: using categorical and continuous variables foreach loop for univaraite analysis Date Mon, 8 Jul 2013 22:51:12 -0400

```Hi,

I apologize, I should have told you that I have tried the solution
suggested by Phil prior to posting the question and I get an error

************************************************************
foreach x of varlist i.cat1 i.cat2 con1 con2 {
logit outcome `x'
}

factor variables not allowed
r(101);

end of do-file
************************************************************

Regarding Dimitri's solution, I have unequal number of categorical and
continuous variables.hence, will not be able to use the solution.

Thank you again for your time and consideration

Mike

On Mon, Jul 8, 2013 at 7:47 PM, Phil Clayton
<philclayton@internode.on.net> wrote:
> One simple solution is a slight tweak to your -foreach- syntax:
>
> foreach x in i.cat1 i.cat2 i.cat3 i.cat4 con1 con2 con3 con4 {
>         logit outcome `x'
> }
>
> Phil
>
> On 09/07/2013, at 8:51 AM, Michael Stewart <michaelstewartresearch@gmail.com> wrote:
>
>> Hello all,
>>
>> In my research project, I have a number of categorical predictors(cat1
>> cat2 cat3 cat4 ) and continuous predictors(con1 con2 con3 con4) and
>> during initial uni-variate analysis,  I am using two step process to
>> evaluate for statistical significance.My code is a follows
>>
>> I use stata 12
>>
>> *********************MY CODE ********************
>> foreach x of varlist cat1 cat2 cat3 cat4{
>> logit outcome i.`x'
>> }
>>
>> foreach x of varlist con1 con2 con3 con4{
>> logit outcome `x'
>> }
>> ********************************************************
>> Question:
>>
>> Is it possible to achieve this is one step i.e., use continuous and
>> predictors as a single varlist but perform logistic regression still
>> respecting the fact that  some are categorical variables and some are
>> continuous variables
>>
>> --
>> Yours Sincerely,
>> Mike.
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> *   http://www.ats.ucla.edu/stat/stata/
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/

--
Thank you ,
Yours Sincerely,
Mike.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```