# Graph bar X, stack over Support

#### belfagor71

##### New Member
Hi there,

am having some problems in doing a graph bar where the different values of one continuous variables are stack over another variable, lest say, state.

So basically if I type this command
graph bar fluor_1, stack over (state_name) percentage

(fluor_1 is the level of fluoride in a given water source and it has 6 different codes)
I get a graph where the codes are not stack at all.

To get a graph with stack columns, I have first to
tab fluor_1, gen (f)
and then
graph bar f1 f2 f3 f4 f5 f6, stack over (state)

So basically, unless I do so, Stata does not understand that i want that variable to be stack.

However to do this for every single variable I want to stack, is quite tedious and I end up with having a lots of variables which I ultimately don't need. Is there any other way to make Stata read that variable in the way I need without generating a new variable?

Hope it makes sense....

Thanks a lot!!!

Hoping to hear from you!

belfagor

#### belfagor71

##### New Member
No, it does not work.
This is what I typed:

graph bar hh_house_type, stack over (state_name) asyvars percentage

#### bukharin

##### RoboStataRaptor
Sorry, I'm not entirely clear what you're graphing... but often for -graph bar- I find it's helpful to create a fake "frequency" variable equal to 1. You can then use its sum or mean for various graphs.

For example:
Code:
sysuse auto
gen byte freq=1
graph bar (sum) freq, stack asyvars percentage over(rep78) over(foreign)
Is that more what you're after?

#### bukharin

##### RoboStataRaptor
Okay, so you need to adapt the example I just gave. Something like:
Code:
gen byte freq=1
graph bar (sum) freq, over(fluor_1) asyvars stack percentages over(state_name)

#### belfagor71

##### New Member
Ok, thanks a lot! It does work now! So basically I can use this new var freq for every other of such graphs, right?
But how come stata does not automatically recognize that I want that var to be stack on the other one? After all, the var fluor_1 has 6 different codes!

#### bukharin

##### RoboStataRaptor
Ok, thanks a lot! It does work now! So basically I can use this new var freq for every other of such graphs, right?
Yes - I use that trick a fair bit when dealing with -graph bar-

But how come stata does not automatically recognize that I want that var to be stack on the other one? After all, the var fluor_1 has 6 different codes!
I could give you a technical answer but the bottom line is that -graph bar- is evil and was designed to inflict pain on Stata users (who are otherwise spoilt with quite nice graphing capabilities!)

#### belfagor71

##### New Member
Code:
(who are otherwise spoilt with quite nice graphing capabilities!)
very true indeed
Code:
graph bar- is evil and was designed to inflict pain on Stata users
agreed!

Help i post hoc

Last edited:

#### belfagor71

##### New Member
sorry but you should post it in a relevant section...