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 |
Nick Cox <njcoxstata@gmail.com> |

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

Subject |
Re: st: Fwd: how to use the label of oldvar to name newvar |

Date |
Mon, 15 Apr 2013 00:49:06 +0100 |

Not necessary. You can -collapse- with its -by()- option. Nick njcoxstata@gmail.com On 14 April 2013 22:21, anne broe <annebroe@gmail.com> wrote: > To be able to make a prevalence for each drug using collapse (sum) > > > 2013/4/14 Nick Cox <njcoxstata@gmail.com>: >> Why do (you think) you need 40 new variables? >> Nick >> njcoxstata@gmail.com >> >> >> On 14 April 2013 20:07, anne broe <annebroe@gmail.com> wrote: >>> I have tried to egen, group option with the label, and that ends up >>> with the same problem as when I just use the encode option. >>> >>> My data looks like this >>> >>> atc >>> "aaabbc01" >>> "aaabcc02" >>> "aaabbc04" >>> "bbbcdd01" >>> etc (40 different total) >>> >>> When I use encode atc, gen(n_atc) it becomes >>> n_atc >>> 1 with value label "aaabbc01" >>> 2 with value label "aaabcc02" >>> 3 with value label "aaabbc04" >>> etc >>> >>> Then I have used gen atc_`xx' = 1 if n_atc==`xx' //xx >>> being the values of n_atc (1-40) >>> But instead of atc_xx I would like my 40 new variables to be named >>> after the original string values e.g. the first var will then be named >>> "aaabbc01" >>> >>> hope you can help me :) >>> >>> 2013/4/14 Nick Cox <njcoxstata@gmail.com>: >>>> Alternatively, you may just be missing out on -egen, group()- with the >>>> -label()- option. >>>> Nick >>>> njcoxstata@gmail.com >>>> >>>> >>>> On 14 April 2013 14:34, Nick Cox <njcoxstata@gmail.com> wrote: >>>>> When you say "the label" are you referring to value labels or variable labels? >>>>> >>>>> Can you give an equivalent example with a dataset we can all access e.g. >>>>> >>>>> sysuse auto >>>>> Nick >>>>> njcoxstata@gmail.com >>>>> >>>>> >>>>> On 14 April 2013 14:29, anne broe <annebroe@gmail.com> wrote: >>>>>> Dear all >>>>>> >>>>>> I am encoding a string var atc to a numeric var n_atc to enable the >>>>>> use of forvalues. >>>>>> In each loop i generate a newvar called atc_`xx' if atc== `xx' and >>>>>> collapse (sum) of this variable. >>>>>> My problem however that instead of atc_`xx' I would like the variable >>>>>> to be named after the original string var atc which equals the label >>>>>> of n_atc. >>>>>> >>>>>> Is there anyway you can use the `xx' to identify to variable and then >>>>>> name it after the label? >>>>>> >>>>>> Hope someone can help me >>>>>> Thanks >>>>>> Anne >>>>>> * >>>>>> * For searches and help try: >>>>>> * http://www.stata.com/help.cgi?search >>>>>> * http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Fwd: how to use the label of oldvar to name newvar***From:*anne broe <annebroe@gmail.com>

**Re: st: Fwd: how to use the label of oldvar to name newvar***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: Fwd: how to use the label of oldvar to name newvar***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: Fwd: how to use the label of oldvar to name newvar***From:*anne broe <annebroe@gmail.com>

**Re: st: Fwd: how to use the label of oldvar to name newvar***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: Fwd: how to use the label of oldvar to name newvar***From:*anne broe <annebroe@gmail.com>

- Prev by Date:
**Re: st: drop duplicates iff** - Next by Date:
**Re: st: How do I demonstrate that a sample is randomly drawn from a population?** - Previous by thread:
**Re: st: Fwd: how to use the label of oldvar to name newvar** - Next by thread:
**st: Oaxaca: error with 2 large sets of categorical variables** - Index(es):