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]

From |
"Gosse, Michelle" <Michelle.Gosse@foodstandards.gov.au> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

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

Date |
Fri, 29 Jul 2011 07:00:23 +1000 |

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/

**Follow-Ups**:**Re: st: labelling values where there is a continuous range [SEC: UNCLASSIFIED]***From:*Fernando Rios Avila <f.rios.a@gmail.com>

- Prev by Date:
**Re: st: Question about graph bar** - Next by Date:
**Re: st: labelling values where there is a continuous range [SEC: UNCLASSIFIED]** - Previous by thread:
**st: Question about graph bar** - Next by thread:
**Re: st: labelling values where there is a continuous range [SEC: UNCLASSIFIED]** - Index(es):