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 |
Maarten Buis <maartenlbuis@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: FW: Possible to generate a variable and specifying the label? |

Date |
Thu, 24 Nov 2011 10:00:07 +0100 |

On Thu, Nov 24, 2011 at 6:30 AM, J. J. W. wrote: > I would like to > generate a variable including specifying the label name<snip>. > Now I've looked at the following: > http://www.stata.com/help.cgi?gen and came to the conclusion that generate > [type] newvar[:lblname] =exp [if] [in] is the command I was looking for. I > tried the following: <snip> > Could someone give an example of how to correct do this? See the example below: First I open a dataset, in this case I use one of the example datasets available in Stata, which can be conveniently accessed with -sysuse-. Than I define the label name. The label name refers to a set of value labels, so I need to define that first before I can use them in -generate-. This is what I did with the -label define command. So now there is the -generate- command, which I usually abreviate with -gen-. The second word in that command specifies the storrage type, in this case byte. You can read more about datatypes by typing in Stata -help data_types-. The third word is the new variable name, and after the colon there is the name of the value label. Then after the equal sign follows the content of the variable, in this case a reversed version of the indicator/dummy variable foreign. *-------------------- begin example ------------- sysuse auto, clear label define dom 0 "foreign" 1 "domestic" gen byte domestic:dom = -1*(foreign-1) *------------------ end example --------------- (For more on examples I sent to the Statalist see: http://www.maartenbuis.nl/example_faq ) Hope this helps, Maarten -------------------------- Maarten L. Buis Institut fuer Soziologie Universitaet Tuebingen Wilhelmstrasse 36 72074 Tuebingen Germany http://www.maartenbuis.nl -------------------------- * * 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/

**References**:**st: FW: Possible to generate a variable and specifying the label?***From:*"J. J. W." <bsc.j.j.w@gmail.com>

- Prev by Date:
**st: Poisson residuals** - Next by Date:
**Re: st: barcharts with error plot + legend?** - Previous by thread:
**Re: st: RE: RE: FW: Possible to generate a variable and specifying the label?** - Next by thread:
**st: stpm2 and interval censoring** - Index(es):