Dear all,
As a new user of Stata I would appreciate any suggestions to create error bars for 4 variables in my dataset for 12 food products. I am getting close to want I am looking for, but I am unable to separate the bars for the 4 variables. My 4 variables are: 1) q31_color_ 2) q32_taste_ 3) q33_texture_ texture; and 4) question 34: smell. With the products codes: 1,2,3,4,5,6,7,8,9,10,11,12.
I used this link to get started: https://stats.idre.ucla.edu/stata/fa...th-error-bars/
And currently I am using the following steps and commands:
1) collapse command to make the mean and standard deviation by product code:
collapse (mean) meanq31_color_=q31_color_ meanq32_taste_=q32_taste_ meanq33_texture_=q33_texture_ meanq34_smell_=q34_smell_ ///
sd) sdq31_color_=q31_color_ sdq32_taste_=q32_taste_ sdq33_texture_=q33_texture_ sdq34_smell_=q34_smell_ ///
count) n=q31_color_ q32_taste_ q33_texture_ q34_smell_ ///
, by(code_product)
2) make the upper and lower values of the confidence interval:
generate hicolorlikeability = meanq31_color_ + invttail(n-1,0.025)*(sdq31_color_ / sqrt(n))
generate hitastelikeability = meanq32_taste_ + invttail(n-1,0.025)*(sdq32_taste_ / sqrt(n))
generate hitexturelikeability = meanq33_texture_ + invttail(n-1,0.025)*(sdq33_texture_ / sqrt(n))
generate hismelllikeability = meanq34_smell_ + invttail(n-1,0.025)*(sdq34_smell_ / sqrt(n))
generate lowcolorlikeability = meanq31_color_ - invttail(n-1,0.025)*(sdq31_color_ / sqrt(n))
generate lowtastelikeability = meanq32_taste_ - invttail(n-1,0.025)*(sdq32_taste_ / sqrt(n))
generate lowtexturelikeability = meanq33_texture_ - invttail(n-1,0.025)*(sdq33_texture_ / sqrt(n))
generate lowsmelllikeability = meanq34_smell_ - invttail(n-1,0.025)*(sdq34_smell_ / sqrt(n))
3) create error bars
graph twoway (bar meanq31_color_ code_product) (rcap hicolorlikeability lowcolorlikeability code_product) ///
bar meanq32_taste_ code_product) (rcap hitastelikeability lowtastelikeability code_product) ///
bar meanq33_texture_ code_product) (rcap hitexturelikeability lowtexturelikeability code_product) ///
bar meanq34_smell_ code_product) (rcap hismelllikeability lowsmelllikeability code_product)

The results gives me the error bars for each product, but the 4 variables are ‘stack’ and I would like to get separate bar for each variable: color, taste, texture and smell for each product. Similar to the graph below:
I started with .twoway (bar meanq31_color_ code_product if code_product==1) etc. to get it fixed, but this is not working out.
Any help would be greatly appreciated. Thank you!
As a new user of Stata I would appreciate any suggestions to create error bars for 4 variables in my dataset for 12 food products. I am getting close to want I am looking for, but I am unable to separate the bars for the 4 variables. My 4 variables are: 1) q31_color_ 2) q32_taste_ 3) q33_texture_ texture; and 4) question 34: smell. With the products codes: 1,2,3,4,5,6,7,8,9,10,11,12.
I used this link to get started: https://stats.idre.ucla.edu/stata/fa...th-error-bars/
And currently I am using the following steps and commands:
1) collapse command to make the mean and standard deviation by product code:
collapse (mean) meanq31_color_=q31_color_ meanq32_taste_=q32_taste_ meanq33_texture_=q33_texture_ meanq34_smell_=q34_smell_ ///
sd) sdq31_color_=q31_color_ sdq32_taste_=q32_taste_ sdq33_texture_=q33_texture_ sdq34_smell_=q34_smell_ ///
count) n=q31_color_ q32_taste_ q33_texture_ q34_smell_ ///
, by(code_product)
2) make the upper and lower values of the confidence interval:
generate hicolorlikeability = meanq31_color_ + invttail(n-1,0.025)*(sdq31_color_ / sqrt(n))
generate hitastelikeability = meanq32_taste_ + invttail(n-1,0.025)*(sdq32_taste_ / sqrt(n))
generate hitexturelikeability = meanq33_texture_ + invttail(n-1,0.025)*(sdq33_texture_ / sqrt(n))
generate hismelllikeability = meanq34_smell_ + invttail(n-1,0.025)*(sdq34_smell_ / sqrt(n))
generate lowcolorlikeability = meanq31_color_ - invttail(n-1,0.025)*(sdq31_color_ / sqrt(n))
generate lowtastelikeability = meanq32_taste_ - invttail(n-1,0.025)*(sdq32_taste_ / sqrt(n))
generate lowtexturelikeability = meanq33_texture_ - invttail(n-1,0.025)*(sdq33_texture_ / sqrt(n))
generate lowsmelllikeability = meanq34_smell_ - invttail(n-1,0.025)*(sdq34_smell_ / sqrt(n))
3) create error bars
graph twoway (bar meanq31_color_ code_product) (rcap hicolorlikeability lowcolorlikeability code_product) ///
bar meanq32_taste_ code_product) (rcap hitastelikeability lowtastelikeability code_product) ///
bar meanq33_texture_ code_product) (rcap hitexturelikeability lowtexturelikeability code_product) ///
bar meanq34_smell_ code_product) (rcap hismelllikeability lowsmelllikeability code_product)
The results gives me the error bars for each product, but the 4 variables are ‘stack’ and I would like to get separate bar for each variable: color, taste, texture and smell for each product. Similar to the graph below:
I started with .twoway (bar meanq31_color_ code_product if code_product==1) etc. to get it fixed, but this is not working out.
Any help would be greatly appreciated. Thank you!