Using Stata to Create Scatterplots

Поделиться
HTML-код
  • Опубликовано: 27 окт 2024

Комментарии • 20

  • @jonasjohajohanson9517
    @jonasjohajohanson9517 9 лет назад

    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!

    • @smilex3
      @smilex3  9 лет назад

      +Jonas Joha Johanson I'm glad you found the videos useful. If you hce ideas for new video topics about Stata, let me know.

  • @stillnupey02
    @stillnupey02 9 лет назад

    Thank you Alan, this was an awesome tutorial and I usually hate graphing in Stata!

    • @smilex3
      @smilex3  9 лет назад

      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.

  • @houdasbaa4368
    @houdasbaa4368 7 лет назад

    Thank you for your excellent tutorials!

    • @smilex3
      @smilex3  7 лет назад +1

      I'm glad you found these videos useful!

  • @robertkolesar7917
    @robertkolesar7917 8 лет назад

    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

    • @smilex3
      @smilex3  8 лет назад +1

      +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

  • @valentynakalonova5093
    @valentynakalonova5093 7 лет назад

    Thanks very much! Did help!

  • @ananggunawan2454
    @ananggunawan2454 5 лет назад

    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?

    • @smilex3
      @smilex3  5 лет назад

      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

    • @ananggunawan2454
      @ananggunawan2454 5 лет назад

      @@@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.

  • @seribelz
    @seribelz 8 лет назад

    thank you very much for your video, does this work for data panel?

    • @smilex3
      @smilex3  8 лет назад

      +seribelz Yes, the same principles can be applied.

  • @AbdulahadSapai
    @AbdulahadSapai 9 лет назад

    thanks Alan, I am struggling how to use if condition in scatter plot

    • @smilex3
      @smilex3  9 лет назад +2

      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

    • @AbdulahadSapai
      @AbdulahadSapai 9 лет назад +1

      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

  • @-summer5825
    @-summer5825 8 лет назад

    How can I add the formula to the graph?

    • @smilex3
      @smilex3  8 лет назад +1

      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")

    • @-summer5825
      @-summer5825 8 лет назад

      Alan, thank you so much!