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 
 
Diederik van Liere <[email protected]> 
To 
 
"[email protected]" <[email protected]> 
Subject 
 
Re: st: width() invalid error when using a local macro to loop over years 
Date 
 
Fri, 7 Jan 2011 12:49:37 -0500 
Dear Stata list members, dear Nick,
Thanks for pointing me to the appropriate vocabulary! 
Indeed, there was no data for a particular combination. Although I do find the error message not very clear.
Because the error message suggests that a particular date is invalid while the date is not invalid there are just no observations. 
Thanks for your help!
Best,
Diederik
>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/
*
*   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/