How to convert a categorical variable into dummies

For technical questions regarding estimation of single equations, systems, VARs, Factor analysis and State Space Models in EViews. General econometric questions and advice should go in the Econometric Discussions forum.

Moderators: EViews Gareth, EViews Moderator

neophytosk
Posts: 16
Joined: Fri Mar 22, 2013 3:44 am

How to convert a categorical variable into dummies

Postby neophytosk » Wed May 15, 2013 4:40 pm

Dear all,

I have the following question.

Background

I have a timeseries dataset regarding fx trades with different counterparties as below. Key variables are the categorical variable 'counterparty type' indicating which is the originating side of a trade (who is trading), and some numerical variables, for illustration below I included flow(is the counterparty buying or selling).

My current dataset set looks as below:

time Currency counterparty type buy/sell
9am eur/usd bank 1
10am eur/usd corporate -1
11am eur/usd non bank financial -1
12pm eur/usd government 1
1pm eur/usd corporate 1


Question

Could you tell me how I can convert the categorical variable automatically to several dummies, each counterparty type should be a dummy with a 1 or 0 indicating whether there is a trade or not.(also all other variables need to be adjusted accordingly to the new structure e.g variable flow)

For illustration the code should convert the table to the below structure:

time Currency bank corporate non bank financial government buy/sell
9am eur/usd 1 0 0 0 1
10am eur/usd 0 1 0 0 -1
11am eur/usd 0 0 1 0 -1
12pm eur/usd 0 0 0 1 1
1pm eur/usd 0 1 0 0 1


I am aware of the @expand function however it only works within a regression framework and beforing running a regression I would liketo make some more changes to the basic dataset, e-g frequency compunding etc

Hope you are able to help - thanks!

Best

Neo

startz
Non-normality and collinearity are NOT problems!
Posts: 3797
Joined: Wed Sep 17, 2008 2:25 pm

Re: How to convert a categorical variable into dummies

Postby startz » Wed May 15, 2013 5:15 pm


I have a timeseries dataset regarding fx trades with different counterparties as below. Key variables are the categorical variable 'counterparty type' indicating which is the originating side of a trade (who is trading), and some numerical variables, for illustration below I included flow(is the counterparty buying or selling).

My current dataset set looks as below:

time Currency counterparty type buy/sell
9am eur/usd bank 1
10am eur/usd corporate -1
11am eur/usd non bank financial -1
12pm eur/usd government 1
1pm eur/usd corporate 1


Question

Could you tell me how I can convert the categorical variable automatically to several dummies, each counterparty type should be a dummy with a 1 or 0 indicating whether there is a trade or not.(also all other variables need to be adjusted accordingly to the new structure e.g variable flow)
series bank = @recode(counterparty="bank",1,0)

neophytosk
Posts: 16
Joined: Fri Mar 22, 2013 3:44 am

Re: How to convert a categorical variable into dummies

Postby neophytosk » Wed May 15, 2013 11:20 pm

Hi Statz,

Thnx for the reply.

However to convert the counterparty type with the recode function I need to re write the command for all counterparty types in the variable.My example was very simplified. I am looking for a code to do this since I have many categorcial variables to convert into dummies and each one of them has 7-8 different types. Is there a more efficient way to do this?

Neo

startz
Non-normality and collinearity are NOT problems!
Posts: 3797
Joined: Wed Sep 17, 2008 2:25 pm

Re: How to convert a categorical variable into dummies

Postby startz » Thu May 16, 2013 6:19 am

You can create a group with

Code: Select all

group g @expand(counterparty)
and then refer to the series within that group as g(1), g(2), etc.


Return to “Estimation”

Who is online

Users browsing this forum: No registered users and 2 guests