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]

st: RE: generate rolling proportions with foreach using an MI dataset


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: generate rolling proportions with foreach using an MI dataset
Date   Wed, 2 Nov 2011 13:27:15 +0000

The -over()- option of -proportion- expects a varlist, namely variable name(s). 1985 is not a variable name. This is nothing to do with imputation, looping or rolling. The error message points directly to the error. 

But I don't see that you need to specify -over()- at all. Your -inrange()- option is designed to give you rolling. 

Nick 
[email protected] 

Tim Evans

I am trying to obtain proportions of a variable over time using an MI dataset in Stata 11.2, this I achieve using:


mim: proportion stage if _mj>0, over(year)

However, each single year does not contain as many cases as I would like, so I would like to combine 5 years of data for eahc data point like:

1985-1989
1986-1990
1987-1991
1988-1992

and so on. I've tried to do this with a foreach loop but cant seem to get it to work, I'd appreciate any advice.

Current code:

forvalues startyear=1985(1)2005 {
mim: proportion stage if _mj>0 & inrange(year,`startyear',`startyear'+4), over(`startyear')

}

This is the output:

. forvalues startyear=1985(1)2005 {
  2. mim: proportion stage if _mj>0 & inrange(year,`startyear',`startyear'+4), over(`startyear')
  3. 
. }
[note: using ice-style format variables _mi and _mj]
-> _mj==1
-> proportion stage if _mj>0 & inrange(year,1985,1985+4), over(1985)
1985 invalid name
invalid over() option
r(198);

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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