Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Creating dummy variables for country dataset


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: Creating dummy variables for country dataset
Date   Sun, 16 Jan 2011 21:41:16 +0000

<>

My examples give the exact same outcome as your code (it just saves the OP a couple of -gen-/-replace- lines of code), for example:

************
webuse grunfeld, clear
**Booth
ta company if inlist(company, 2) , g(c)   //companies 4, 7, 8 removed for illustration//
recode c1 (.=0)
**de Souza
gen company2 = 0
replace company2 = 1 if company == 2
**
l if company2!=c1
************

As for the wisdom of recoding missings to zero, this depends on what the OP plans to do with the new variables (i.e., are they used for running a model, -egen-ing some calculation, or flagging some of the companies for data management ?)  If the OP wishes to makes them missing, then they could comment out the -recode- line in my example, or change de Souza's line "gen company2 = 0" to "gen company2 = ." .  


- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754

On Jan 16, 2011, at 6:05 AM, DE SOUZA Eric wrote:

> 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: [email protected] [mailto:[email protected]] On Behalf Of Eric Booth
> Sent: 16 January 2011 08:06
> To: <[email protected]>
> 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
> [email protected]
> 
> 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: [email protected] 
>> [mailto:[email protected]] On Behalf Of Saudamini 
>> Dabak
>> Sent: 15 January 2011 18:12
>> To: [email protected]
>> 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index