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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

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

Subject |
Re: st: Create a new variable based on some other variables |

Date |
Wed, 20 May 2009 21:11:40 +0200 |

<> ***** clear* set obs 100 local a 1 local b 8 forv i=1/3{ gen A`i'=`a'+/* */int((`b'-`a'+1)*runiform()) } compress

gen B=(A1==1)*1 replace B=(A2==3)*2 replace B=(A3==8)*3 ***** HTH

To: <statalist@hsphsun2.harvard.edu> Sent: Wednesday, May 20, 2009 9:00 PM Subject: Re: st: Create a new variable based on some other variables

gen b =. replace b=1 if a1==1 replace b=2 if a2==3 replace b=3 if a3==8 On May 20, 2009, at 1:56 PM, Charles Man@CCR wrote:Dear Statalisters,If I want to create a new variable based on the values of a fewother variables, how can I do that?For instance, Create B If A1=1, then B=1 If A2=3, then B=2 If A3=8, then B=3 Can -gen- or -egen- or -recode- do this job? Thanks, Charles * * 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/

* * 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: Create a new variable based on some other variables***From:*"Charles Man@CCR" <ccrman@cityu.edu.hk>

**Re: st: Create a new variable based on some other variables***From:*"Eric A. Booth" <ebooth@ppri.tamu.edu>

- Prev by Date:
**Re: st: Create a new variable based on some other variables** - Next by Date:
**RE: st: how to get the "tabdis" result in datasheet?** - Previous by thread:
**Re: st: Create a new variable based on some other variables** - Next by thread:
**st: Re: Create a new variable based on some other variables** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |