Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Fernando Rios Avila <f.rios.a@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Thu, 28 Jul 2011 17:05:35 -0400 |

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/

**Follow-Ups**:**RE: st: labelling values where there is a continuous range [SEC: UNCLASSIFIED]***From:*"Gosse, Michelle" <Michelle.Gosse@foodstandards.gov.au>

**References**:**st: labelling values where there is a continuous range [SEC: UNCLASSIFIED]***From:*"Gosse, Michelle" <Michelle.Gosse@foodstandards.gov.au>

- Prev by Date:
**st: labelling values where there is a continuous range [SEC: UNCLASSIFIED]** - Next by Date:
**Re: st: DO editor crash - linux** - Previous by thread:
**st: labelling values where there is a continuous range [SEC: UNCLASSIFIED]** - Next by thread:
**RE: st: labelling values where there is a continuous range [SEC: UNCLASSIFIED]** - Index(es):