Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | DE SOUZA Eric <eric.de_souza@coleurope.eu> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | RE: st: Creating dummy variables for country dataset |
Date | Sun, 16 Jan 2011 13:05:47 +0100 |
I thought about missing values. But do you want to recode the missing values to zero? If observations are missing, they should stay out. Eric Eric de Souza College of Europe Brugge (Bruges), Belgium http://www.coleurope.eu -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Eric Booth Sent: 16 January 2011 08:06 To: <statalist@hsphsun2.harvard.edu> Subject: Re: st: Creating dummy variables for country dataset <> You can still use -tab- to generate the dummies with an 'if' condition, but you'll need to recode the new dummies' missings to zero: ************ webuse grunfeld, clear ta company if inlist(company, 2, 4, 7, 8) , g(c) recode c1-c4 (.=0) ************ If you end up wanting to generate more than 3 dummies (but still not for all 213 countries), then you could do something like this to work with a longer list: ************ cap drop c1-c4 foreach n in 2 4 7 8 9 { mark c`n' if company==`n' } ************ Finally, keep in mind that you can skip creating the dummy variables & specify the categories of interest using the factor variable syntax: ************ regress invest mvalue i(2 4 7 8).company h fvvarlist // <-- for more this syntax ************ - Eric __ Eric A. Booth Public Policy Research Institute Texas A&M University ebooth@ppri.tamu.edu On Jan 15, 2011, at 3:19 PM, DE SOUZA Eric wrote: > webuse grunfeld > gen company2 = 0 > replace company2 = 1 if company == 2 > > The variable company numbers companies from 1 to ... > The above creates a variable company2 which equals 0 everywhere except > for company number 2 > > Eric > > > Eric de Souza > College of Europe > Brugge (Bruges), Belgium > http://www.coleurope.eu > > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Saudamini > Dabak > Sent: 15 January 2011 18:12 > To: statalist@hsphsun2.harvard.edu > Subject: <SPAM>st: Creating dummy variables for country dataset > > Hi > > > thanks for the help earlier! > > > i need to create dummy variables for 3 countries out of 213 from a panel data with 6 variables. I tried using the tabulate function but that generates dummy variables for all the countries, which is very cumbersome. > > Any ideas, other than retrying in excel? > > thanks a tonne! > > -Saudamini > * > * 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/ * * 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/