How to convert a categorical variable into dummies
Posted: 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
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