Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

RE: st: labelling values where there is a continuous range [SEC: UNCLASSIFIED]


From   "Gosse, Michelle" <Michelle.Gosse@foodstandards.gov.au>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: labelling values where there is a continuous range [SEC: UNCLASSIFIED]
Date   Fri, 29 Jul 2011 07:16:15 +1000

Thanks so much for the advice, this worked perfectly:

recode ADD_SUG (0= 0 zero) (0.0000001/300 = 1 >0), gen(newADD_SUG)

cheers
Michelle

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Fernando Rios Avila
Sent: Friday, 29 July 2011 9:06 AM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: labelling values where there is a continuous range [SEC: UNCLASSIFIED]

Hi Michelle,
I think you should look at -help recode-. Here you can create the new variable that would contain the new variable after being regrouped, and also include your labels.
Fernando

On Thu, Jul 28, 2011 at 5:00 PM, Gosse, Michelle <Michelle.Gosse@foodstandards.gov.au> wrote:
> Greetings,
>
> I am new to Stata and am finding the language and menus quite easy to use, apart from this problem which has thrown me. I am using Stata 11.2 SE, in a networked environment.
>
> I have some added sugar intake data (for humans) and I would like to output a frequency table that gives in a count against a subclassification of the values, otherwise I would have an extremely large number of rows in my table. I'm trying to translate from SAS code, and I thought I could achieve the same result by using labels to define the table rows, but I've run into issues as I need to define a range as part of a label.
>
> The relevant SAS code is:
> ---------------------------------
> proc format;
> value nonzerof
>         0 = '0'
>    0.000001-1000 = '  > 0 ';
>
> proc freq data=nhanes;
>  tables r_add_sug*add_sug/missing list;
>  format add_sug nonzerof.;
>  title4 'Check zero consumption before replacing zero consumption with 
> half of the minimum amount on a consumption day';
>  run;
> ----------------------------------
>
> So far I have tried various ways to implement an equivalent label format in Stata, using for, but I keep getting a syntax error:
> ------------------------------------------
> . label define nonzerof  0 "0" for 0.000001/1000 "> 0"
> invalid syntax
> r(198);
>
> . label define nonzerof  0 "0" forvalues i=0.000001/1000 {"> 0"} 
> invalid syntax r(198);
> ------------------------------------------
>
> (I was then going to use the command:
> label value nonzerof add_sug)
>
> before I ran the frequency table to get the output I need. But I can't get my label command to work. What do I need to change to make the label "> 0" apply to add_sug values between 0.000001 and 1000? I think I need to step through the values, but I'm not sure how to make the forvalues function to work. I'm also not sure that the forvalues command is the one I should be using, nor do I understand how to make the syntax work with the first specification that 0="0"
>
> I was hoping that someone might have an example of how to implement this with labelling that I can use. I have done a Google search and looked through some Stata email archives, but I can't locate a worked example that I could plagarise.
>
> The add_sug variable contains up to 7 decimal places, and so I assume I need to step through that number of significant places.
>
> Finally, does every value in the range need to be in the dataset, or 
> just the start and end values (or not even those)? The actual range of 
> values is 0 to 263.7918
>
> Cheers
> Michelle
>
>
> UNCLASSIFIED
> **********************************************************************
> This email and any files transmitted with it are confidential and 
> intended solely for the use of the individual or entity to whom they 
> are addressed. If you have received this email in error please notify 
> the system manager.
>
> This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses.
> **********************************************************************
>
>
> *
> *   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/

UNCLASSIFIED

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index