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: width() invalid error when using a local macro to loop over years


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: width() invalid error when using a local macro to loop over years
Date   Fri, 7 Jan 2011 09:17:29 +0000

On the word "macro" and what it means in Stata, see

<http://www.stata.com/statalist/archive/2008-08/msg01258.html>

On your query: for one of your dates, I guess that there are no data.

histogram experience if date==mdy(1, 30, `year'), discrete percent

itself is legal and the fact that you are doing this within a loop is
completely incidental.

A fix is to go

noisily capture histogram experience if date==mdy(1, 30, `year'),
discrete percent

That aside, you want at most 11 histograms. Using a -by()- option
would let you compare them more easily. Also check out -stripplot-
(SSC).

Nick

On Thu, Jan 6, 2011 at 10:27 PM, Diederik van Liere

> I would like to dynamically generate dates for a simple macro. The dataset contains two variables: experience and date. Experience is a simple count variable and date is the date of observation. I would like to generate a number of histograms for different years.  The current code to do this looks:
>
>
> forvalues year = 2001(1)2011 {
>        histogram experience if date==mdy(1, 30, `year'), discrete percent
> }
>
> However, this does not work. Stata raises the following error:
>        width() invalid -- invalid number, outside of allowed range.
> I am not quite sure why this is the case, wrapping the year variable like "`year'" does not solve the problem either.
>
> Any suggestions on how to fix this?

*
*   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