Dear Alan I just watched a whole bunch of your videos about editing STATA grafics. I just want you to know that I'm very thankful for your videos. I really appreciate your work. You helped me a lot with my own grafic design. I wish you all the best. Thanks again!
Eugene Walton I'm glad you found the video useful. I think once you get the basics of creating data visualizations in Stata, it is a pretty great tool.
Alan- your videos are brilliant! I am trying to create a tw Scatterplot with both vars as integers from 1-10. As I have 1000s of observations, the graphic is just piling them up. I used jitter, but want to know if there is a way to weight the size of the circle at each point according to the frequency of observations? Thanks much, Robert
+Robert Kolesar Robert, yes, this is a problem with data that have a limited range. What I usually do is calculate an average of the dependent variables by each value of the independent variable. This can produce illuminating visualizations, but these are averages and averages can his as much as they reveal. Here is some sample code that you may find useful: sysuse auto, clear graph twoway (scatter mpg rep78, name(g1, replace)) preserve collapse mpg if rep78
Hi Allan, thanks for the excellent tutorial. I have a questing about creating scatter of two variables on panel data set with different specific year and a linier line in one graph, especiall on writing the command of "if condition". For example, I want to make scatter plot of two variables, variable foreign and variabel domestic. For variable foreign, I want to use specific year 2017 (in y axis) and for domestic, i want to use specific year 1991 (in x axis). In addition I also want to make a linear line (with the equation) to show the relationship between those two variables. Could show me how to write the stata command for this?
Anang, it is difficult to understand your question without seeing your data. But maybe the following will get you started: graph twoway (scatter foreign2017 domestic2019) (lfit foreign2017 domestic2019) If your data are in wide format something like this should work. If your data are in long format you should use the reshape command (see help reshape) which will put your data in shape to plot what you want. Best, Alan
@@@smilex3 Thank you for your reply. I'll try to explain a bit clearly. Actually, I want to replicate Figure 2 in this paper documents.worldbank.org/curated/en/823731468002999348/pdf/WPS6971.pdf. So far I have data of "ln(manufacturing VA per worker)" from 1991 to 2018 for all countries. To make variable of "change in ln(manufacturing VA per worker), early 1990s to late 2000s" for vertical axis, I generate a new variable using command gen chg_lnind_VAperWorker = (lnind_VAperWorker-L26.lnind_VAperWorker), since I want to see the change from 1991 to 2017. Through that calculation, I will have variable "ln(manufacturing VA per worker)" from 1991 to 2018 and variable chg_lnind_VAperWorker from 2017 and 2018 (the data before 2017 cannot be generated because I do not have data before 1991). Then, I am trying to replicate figure 2 using this basic command graph twoway (scatter chg_lnind_VAperWorker lnGDPPC_PPP if year == 2017) This command give me ""change in ln(manufacturing VA per worker), early 1990s to late 2010s" for the vertical axis and "ln(manufacturing VA per worker), late 2010s" for the horizontal axis. Since I want to see the relationship of "ln(manufacturing VA per worker), late 2010s" {NOT THE early 1990s], then I try to create the command as folows graph twoway (scatter chg_lnind_VAperWorker if year == 2017 & lnGDPPC_PPP if year == 1991) But it doesn't work. So, how to make twoway scatter graph in panel data using different year? Thank you Alan. I really apreciate your help.
Abdulahad Sapai Can you give me a little more detail? The syntax for this kind of visualization is: [twoway] scatter varlist [if] [in] [weight] [, options] Note that anything within brackets ("[]") is optional. Try the following code: sysuse auto, clear graph twoway (scatter mpg weight if foreign==0) /// (scatter mpg weight if foreign==1) See how it is possible to use the -if- qualifier to first plot the domestic cars ("foreign==0") and then the foreign cars ("foreign==1"). Best, Alan
Alan Neustadtl I wanted to visualize proportion of food consumption on Y axis and total consumption expenditure on X axis but split the consumption into two categories say poor and non-poor, to compare spending on food consumption on same plot
Summer, you don't specify what formula you want to display, but Stata does allow Greek letters and some symbols, but no hats ("^") over symbols unless you know how to use unicode. See "help text" for the details which is where I got the following example: twoway function y = gammaden(1.5,2,0,x), range(0 10) /// title("{&chi}{sup:2}(3) distribution")
Dear Alan I just watched a whole bunch of your videos about editing STATA grafics. I just want you to know that I'm very thankful for your videos. I really appreciate your work. You helped me a lot with my own grafic design. I wish you all the best. Thanks again!
+Jonas Joha Johanson I'm glad you found the videos useful. If you hce ideas for new video topics about Stata, let me know.
Thank you Alan, this was an awesome tutorial and I usually hate graphing in Stata!
Eugene Walton I'm glad you found the video useful. I think once you get the basics of creating data visualizations in Stata, it is a pretty great tool.
Thank you for your excellent tutorials!
I'm glad you found these videos useful!
Alan- your videos are brilliant! I am trying to create a tw Scatterplot with both vars as integers from 1-10. As I have 1000s of observations, the graphic is just piling them up. I used jitter, but want to know if there is a way to weight the size of the circle at each point according to the frequency of observations? Thanks much, Robert
+Robert Kolesar Robert, yes, this is a problem with data that have a limited range. What I usually do is calculate an average of the dependent variables by each value of the independent variable. This can produce illuminating visualizations, but these are averages and averages can his as much as they reveal. Here is some sample code that you may find useful:
sysuse auto, clear
graph twoway (scatter mpg rep78, name(g1, replace))
preserve
collapse mpg if rep78
Hi Allan, thanks for the excellent tutorial. I have a questing about creating scatter of two variables on panel data set with different specific year and a linier line in one graph, especiall on writing the command of "if condition". For example, I want to make scatter plot of two variables, variable foreign and variabel domestic. For variable foreign, I want to use specific year 2017 (in y axis) and for domestic, i want to use specific year 1991 (in x axis). In addition I also want to make a linear line (with the equation) to show the relationship between those two variables. Could show me how to write the stata command for this?
Anang, it is difficult to understand your question without seeing your data. But maybe the following will get you started:
graph twoway (scatter foreign2017 domestic2019) (lfit foreign2017 domestic2019)
If your data are in wide format something like this should work. If your data are in long format you should use the reshape command (see help reshape) which will put your data in shape to plot what you want.
Best,
Alan
@@@smilex3 Thank you for your reply. I'll try to explain a bit clearly.
Actually, I want to replicate Figure 2 in this paper documents.worldbank.org/curated/en/823731468002999348/pdf/WPS6971.pdf.
So far I have data of "ln(manufacturing VA per worker)" from 1991 to 2018 for all countries.
To make variable of "change in ln(manufacturing VA per worker), early 1990s to late 2000s" for vertical axis, I generate a new variable using command gen chg_lnind_VAperWorker = (lnind_VAperWorker-L26.lnind_VAperWorker), since I want to see the change from 1991 to 2017.
Through that calculation, I will have variable "ln(manufacturing VA per worker)" from 1991 to 2018 and variable chg_lnind_VAperWorker from 2017 and 2018 (the data before 2017 cannot be generated because I do not have data before 1991).
Then, I am trying to replicate figure 2 using this basic command
graph twoway (scatter chg_lnind_VAperWorker lnGDPPC_PPP if year == 2017)
This command give me ""change in ln(manufacturing VA per worker), early 1990s to late 2010s" for the vertical axis and "ln(manufacturing VA per worker), late 2010s" for the horizontal axis.
Since I want to see the relationship of "ln(manufacturing VA per worker), late 2010s" {NOT THE early 1990s], then I try to create the command as folows
graph twoway (scatter chg_lnind_VAperWorker if year == 2017 & lnGDPPC_PPP if year == 1991)
But it doesn't work.
So, how to make twoway scatter graph in panel data using different year?
Thank you Alan. I really apreciate your help.
Thanks very much! Did help!
thanks Alan, I am struggling how to use if condition in scatter plot
Abdulahad Sapai Can you give me a little more detail? The syntax for this kind of visualization is:
[twoway] scatter varlist [if] [in] [weight] [, options]
Note that anything within brackets ("[]") is optional. Try the following code:
sysuse auto, clear
graph twoway (scatter mpg weight if foreign==0) ///
(scatter mpg weight if foreign==1)
See how it is possible to use the -if- qualifier to first plot the domestic cars ("foreign==0") and then the foreign cars ("foreign==1").
Best,
Alan
Alan Neustadtl I wanted to visualize proportion of food consumption on Y axis and total consumption expenditure on X axis but split the consumption into two categories say poor and non-poor, to compare spending on food consumption on same plot
thank you very much for your video, does this work for data panel?
+seribelz Yes, the same principles can be applied.
How can I add the formula to the graph?
Summer, you don't specify what formula you want to display, but Stata does allow Greek letters and some symbols, but no hats ("^") over symbols unless you know how to use unicode. See "help text" for the details which is where I got the following example:
twoway function y = gammaden(1.5,2,0,x), range(0 10) ///
title("{&chi}{sup:2}(3) distribution")
Alan, thank you so much!