OK. I changed the original variables (1C, 1 L etc) into numeric (1-9)
I have attached a merge file with some of the variables. From this data I
want to make 3 x 2 bar graphs over tank 1-9 showing pre_l, post_l and growth
for female (F) and for male (M).
Thank you for your involvement. I am a bit lost here..
Anne-Christine
On 6/11/07 2:00 PM, "Nick Cox" <[email protected]> wrote:
> This question, as I understand it, has already been
> answered.
>
> Ulrich's example shows that you can -- and indeed
> for many purposes need to -- use -encode- to map
> a string variable to a numeric variable. That is,
> Stata is telling you that a string variable is allowed
> in the way that you have tried; hence you must use
> a numeric variable instead.
>
> It is difficult otherwise to comment on what you
> typed if you don't show it to us.
>
> Nick
> [email protected]
>
> Knag Anne-Christine
>
>> Hi, thank you. But how can I use a twoway when I am plotting just one
>> variable (e.g weight) of different types (1C, 1L etc)?
>> I tried the suggested syntax, but it came up with varlist:
>> type: string
>> variable not allowed
>> ?
>
>> On 6/11/07 1:00 PM, "Nick Cox" <[email protected]> wrote:
>>
>>> You need to move away from -graph bar- once you
>>> want to do something not obviously available.
>>>
>>> -twoway bar- is ultimately more flexible. Ulrich's
>>> example underlines this, so heed his advice.
>>>
>>> Here is a dopey example:
>>>
>>> u auto, clear
>>> egen mean = mean(mpg), by(foreign)
>>> egen sd = sd(mpg), by(foreign)
>>> gen upper = mean + sd
>>> gen lower = mean - sd
>>> twoway bar mean foreign, barw(0.4) || ///
>>> rcap upper lower foreign, xla(0 1, valuelabel) ///
>>> ysc(r(0, .)) legend(off) ///
>>> subtitle(mean +/- sd, place(w)) ytitle(`: var label mpg')
>>>
>>> Biologists in particular seems overly fond of just
>>> showing means (+/- sd, se, or constant * se) in what
>>> Stata user Paul Seed has called detonator plots.
>>>
>>> A dotplot with means and sds added (see -dotplot-)
>>> shows far more information.
>>>
>>> Nick
>>> [email protected]
>>>
>>> Knag Anne-Christine
>>>
>>>> Thank you Ulrich.
>>>> What do I then do if I want to make simple one-way bargraphs
>>>> by the same
>>>> order?
>>>> The syntax (without the order)
>>>>
>>>> graph bar (mean) variable1, over (type)
>>>>
>>>> And how can I add SD to the bars?
>>>
>>>> On 6/8/07 9:51 AM, "Ulrich Kohler" <[email protected]> wrote:
>>>>
>>>>> Knag Anne-Christine wrote:
>>>>>> By "this order" I meant the order that I have given
>>>>>> syntax:
>>>>>> generate order = 1 if type== "1C"
>>>>>> replace order = 2 if type== "1L"
>>>>>> replace order = 3 if type== "1M"
>>>>>> replace order = 4 if type == "1E"
>>>>>> replace order = 5 if type== "2C"
>>>>>> replace order = 6 if type== "2L"
>>>>>> replace order = 7 if type== "2M"
>>>>>> replace order = 8 if type== "2H"
>>>>>> replace order = 9 if type== "2E"
>>>>>>
>>>>>> Since the graphs are ordered alphanumerically I need to
>>>> add an "sort
>>>>>> according to order"-command somewhere in the syntax for
>> the plots:
>>>>>>
>>>>>> twoway (bar production day_of_prod), ytitle(Production)
>>>> xtitle(Day of
>>>>>> production) by(type)
>>>>>>
>>>>>> I also want to include a 10th plot showing the total
>>>> production of all
>>>>>> types.
>>>>>
>>>>> How about:
>>>>>
>>>>> ----------------------------------------------example.do
>>>>> label define order ///
>>>>> 1 "1C" 2 "1L" 3 "1M" 4 "1E" 5 "2C" ///
>>>>> 6 "2L" 7 "2M" 8 "2H" 9 "2E"
>>>>>
>>>>> encode type, gen(order) label(order)
>>>>>
>>>>> twoway ///
>>>>> || bar production day_of_prod ///
>>>>> || , ytitle(Production) xtitle(Day ofproduction) ///
>>>>> by(order, total)
>>>>> ---------------------------------------------------------
>
> *
> * For searches and help try:
> * http://www.stata.com/support/faqs/res/findit.html
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
tank,type,SEX,pre_l,post_l,growth
"1","1K","F","45","45.5",".5"
"1","1K","F","36.5","46.5","10"
"1","1K","F","47","47.5",".5"
"1","1K","F","47","48","1"
"1","1K","F","48","47","-1"
"2","1L","F","40.5","40.5","0"
"2","1L","F","44.5","44.5","0"
"2","1L","F","45","45.5",".5"
"2","1L","F","44","44","0"
"2","1L","F","45","45","0"
"2","1L","F","49","49","0"
"3","1M","F","42","42","0"
"3","1M","F","45.5","46",".5"
"3","1M","F","45.5","46",".5"
"3","1M","F","47","47.5",".5"
"3","1M","F","50","50","0"
"3","1M","F","53","52.5","-.5"
"4","1E","F","45","44","-1"
"4","1E","F","47","47.5",".5"
"4","1E","F","45.5","46",".5"
"4","1E","F","49.5","49.5","0"
"4","1E","F","50.5","51.5","1"
"4","1E","F","48.5","48","-.5"
"5","2K","F","40.5","40",".5"
"5","2K","F","43.5","43",".5"
"5","2K","F","43.5","44","-.5"
"5","2K","F","43","43.5","-.5"
"5","2K","F","48.5","48.5","0"
"5","2K","F","49.5","49.5","0"
"6","2L","F","42","42","0"
"6","2L","F","41.5","42","-.5"
"6","2L","F","44","44.5","-.5"
"6","2L","F","44.5","44.5","0"
"6","2L","F","43.5","43.5","0"
"6","2L","F","48","48.5","-.5"
"7","2M","F","43","43","0"
"7","2M","F","45","45","0"
"7","2M","F","44.5","45","-.5"
"7","2M","F","45","45","0"
"7","2M","F","45","45.5","-.5"
"7","2M","F","49.5","49.5","0"
"8","2H","F","40.5","42","-1.5"
"8","2H","F","44","44.5","-.5"
"8","2H","F","44","44.5","-.5"
"8","2H","F","45","45.5","-.5"
"8","2H","F","46","46.5","-.5"
"8","2H","F","49.5","50","-.5"
"9","2E","F","40","40.5","-.5"
"9","2E","F","41.5","41.5","0"
"9","2E","F","42.5","43","-.5"
"9","2E","F","43","44","-1"
"9","2E","F","43","44","-1"
"9","2E","F","46.5","","46.5"
"1","1K","M","42","",""
"1","1K","M","47.5","48.5","1"
"1","1K","M","46","46.5",".5"
"1","1K","M","45","45","0"
"1","1K","M","46","46.5",".5"
"1","1K","M","45","45.5",".5"
"2","1L","M","41","41.5",".5"
"2","1L","M","43.5","44",".5"
"2","1L","M","43","43.5",".5"
"2","1L","M","45","45","0"
"2","1L","M","44.5","46","1.5"
"2","1L","M","47","48","1"
"3","1M","M","42.5","43.5","1"
"3","1M","M","47","47.5",".5"
"3","1M","M","47","48","1"
"3","1M","M","45.5","48","2.5"
"3","1M","M","48.5","49",".5"
"3","1M","M","46.5","48","1.5"
"4","1E","M","44.5","45",".5"
"4","1E","M","47","48.5","1.5"
"4","1E","M","46","47.5","1.5"
"4","1E","M","47.5","49","1.5"
"4","1E","M","48.5","49",".5"
"4","1E","M","48.5","50","1.5"
"5","2K","M","46","47.5","1.5"
"5","2K","M","47.5","48",".5"
"5","2K","M","45","45.5",".5"
"5","2K","M","44","44","0"
"5","2K","M","45","46","1"
"5","2K","M","46","47","1"
"6","2L","M","41.5","42",".5"
"6","2L","M","42.5","43",".5"
"6","2L","M","43","44","1"
"6","2L","M","45.5","46.5","1"
"6","2L","M","43","43","0"
"6","2L","M","48.5","50","1.5"
"7","2M","M","38.5","39",".5"
"7","2M","M","34.5","45","10.5"
"7","2M","M","43","43.5",".5"
"7","2M","M","45.5","46.5","1"
"7","2M","M","46.5","46.5","0"
"7","2M","M","48.5","49",".5"
"8","2H","M","42.5","43.5","1"
"8","2H","M","41","42","1"
"8","2H","M","45","45","0"
"8","2H","M","44","44","0"
"8","2H","M","45","46.5","1.5"
"8","2H","M","48.5","49.5","1"
"9","2E","M","46","47","1"
"9","2E","M","46","48","2"
"9","2E","M","47","50","3"
"9","2E","M","49","50.5","1.5"
"9","2E","M","47.5","49.5","2"
"9","2E","M","47.5","50","2.5"