Bookmark and Share

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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: -foreach- loop to fit regression at each level of a variable


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: -foreach- loop to fit regression at each level of a variable
Date   Tue, 19 Nov 2013 12:42:39 +0000

Just looking at the help for a few seconds establishes that

1. There is no -levelsof()- function for -egen-.

2. -foreach ... of- requires a key word specifying a list type to follow.

Also you should learn in type in Stata

. search foreach

to find resources. In this case,

http://www.stata.com/support/faqs/data-management/try-all-values-with-foreach/

is most focused on your problem.

Nick
[email protected]


On 19 November 2013 12:34, Milena Przheska
<[email protected]> wrote:

> I am trying to fit the same logistic regression model using different
> samples from a data set and I am wondering if it is even possible to
> use a -foreach- loop to estimate regression models for each sample
> (indicated by a variable).
>
> I use the variable 'sample' to indicate the sample, but instead of
> writing the command over and over for each sample, I tried to do this
> with a -foreach- loop, something  like this:
>
> egen local sample_level = levelsof(sample)
>
> foreach n of sample_level {
> logistic outcome var1 var2 var3 if sample_level==`n', vce(cluster id)
> }
>
> As always, I would appreciate your help.
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index