Hi everyone,
I have a cross section data for a group of countries and three variables: government spending, test scores and regions (please find below an example of the data). I would like to create a scatter plot with two variables (gov spending and test scores) while having different colors for each region and at the same time adding one label for one particular observation.
Example of the data
* Example generated by -dataex-. For more info, type help dataex
clear
input int year str3 code float harmonizedtestscores double govexpstudent str26 region
2020 "ABW" . 17.08119 "Latin America & Caribbean"
2020 "AFG" 354.7588 10.25174 "South Asia"
2020 "ALB" 434.1276 34.18148 "Europe & Central Asia"
2020 "AND" . 12.30702 "Europe & Central Asia"
2020 "ARE" 448.0407 6.04318 "Middle East & North Africa"
2020 "ARG" 408.1726 14.97726 "Latin America & Caribbean"
2020 "ARM" 442.96945 10.15365 "Europe & Central Asia"
2020 "ATG" 406.9974 8.05843 "Latin America & Caribbean"
2020 "AUS" 515.68536 19.30184 "East Asia & Pacific"
2020 "AUT" 507.6394 23.48041 "Europe & Central Asia"
2020 "BDI" 422.7478 12.92904 "Sub-Saharan Africa"
2020 "BEL" 516.80786 21.87767 "Europe & Central Asia"
2020 "BEN" 383.92285 10.25321 "Sub-Saharan Africa"
2020 "BFA" 403.6543 16.13029 "Sub-Saharan Africa"
2020 "BGD" 368.3153 7.56853 "South Asia"
2020 "BGR" 441.0933 22.99728 "Europe & Central Asia"
2020 "BHR" 451.706 11.16362 "Middle East & North Africa"
2020 "BLZ" . 16.55987 "Latin America & Caribbean"
2020 "BMU" . 8.05056 "North America"
2020 "BRA" 413.24475 20.05496 "Latin America & Caribbean"
2020 "BRB" . 20.75168 "Latin America & Caribbean"
2020 "BRN" 437.5159 8.87354 "East Asia & Pacific"
2020 "BTN" 386.7394 12.84915 "South Asia"
2020 "BWA" 391.3183 10.0503 "Sub-Saharan Africa"
2020 "CAF" 368.7302 4.10032 "Sub-Saharan Africa"
2020 "CAN" 533.998 17.56737 "North America"
2020 "CHE" 515.13904 24.78876 "Europe & Central Asia"
2020 "CHL" 452.2182 18.38536 "Latin America & Caribbean"
2020 "CHN" 441 5.90241 "East Asia & Pacific"
2020 "CIV" 373.2305 13.27872 "Sub-Saharan Africa"
2020 "CMR" 378.8688 5.44964 "Sub-Saharan Africa"
2020 "COD" 310.1971 7.19307 "Sub-Saharan Africa"
2020 "COG" 370.6141 11.68812 "Sub-Saharan Africa"
2020 "COL" 419.0275 16.98989 "Latin America & Caribbean"
2020 "COM" 392.2255 9.75717 "Sub-Saharan Africa"
2020 "CPV" . 16.65962 "Sub-Saharan Africa"
2020 "CRI" 428.5557 20.82721 "Latin America & Caribbean"
2020 "CUB" . 49.06773 "Latin America & Caribbean"
2020 "CUW" . 10.00974 "Latin America & Caribbean"
2020 "CYM" . 17.06149 "Latin America & Caribbean"
2020 "CYP" 502.1622 31.88086 "Europe & Central Asia"
2020 "CZE" 512.2216 13.8679 "Europe & Central Asia"
2020 "DEU" 517.28143 17.44257 "Europe & Central Asia"
2020 "DJI" . 37.32327 "Middle East & North Africa"
2020 "DMA" 403.7832 14.64306 "Latin America & Caribbean"
2020 "DNK" 517.8778 25.05246 "Europe & Central Asia"
2020 "DOM" 345.2165 16.18636 "Latin America & Caribbean"
2020 "DZA" 374.0891 11.47531 "Middle East & North Africa"
2020 "ECU" 420.1486 9.51098 "Latin America & Caribbean"
2020 "EGY" 355.9865 9.84518 "Middle East & North Africa"
2020 "ERI" . 5.26822 "Sub-Saharan Africa"
2020 "ESP" 506.6212 17.11832 "Europe & Central Asia"
2020 "EST" 543.20605 20.29085 "Europe & Central Asia"
2020 "ETH" 348.199 7.87686 "Sub-Saharan Africa"
2020 "FIN" 533.70764 21.50883 "Europe & Central Asia"
2020 "FJI" 383.336 12.35277 "East Asia & Pacific"
2020 "FRA" 510.2606 17.3647 "Europe & Central Asia"
2020 "GAB" 456.1277 4.71526 "Sub-Saharan Africa"
2020 "GBR" 520.35645 24.17334 "Europe & Central Asia"
I have used the following code and it works perfectly (please find below an image):
separate harmonizedtestscores ,by( region ) veryshortlabel
scatter harmonizedtestscores? govexpstudent
I just would like to add a label for one country "EGY". I would be grateful if you could advise.
Many thanks in advance.
Jala
Related Posts with Sactter plot with different groups while adding label for one particular observation (sepscatter command)
Generate Unique Group ID in a Panel Data with Spelling VariationsDear Statalist users, I have created a panel dataset based on election results (this is a fairly lar…
Need help with surveysetI have a study using HCUP National Inpatient Sample. My commands were all working until I got to hos…
Independent Variable predicts is highly correlated with dependent variable.I will be very grateful for your help on this issue. Independent Variable (Last Birth CS) is highly …
Merging m:m - it seems to work for me. Why critise? Appreciate your feedbackAs you can see in my previous posts. I currently have one huge dataset called procedure. This shows…
I would like to turn my imperfect edgelist into a perfect one (with all possible pairs of nodes of a network)Hi everyone. To put it very briefly, I have data on different individuals and their connections with…
Subscribe to:
Post Comments (Atom)
0 Response to Sactter plot with different groups while adding label for one particular observation (sepscatter command)
Post a Comment