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   DE SOUZA Eric <[email protected]>
To   "[email protected]" <[email protected]>
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: [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/
> 
> *
> *   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/


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