Sepscatter () and lowess smoothing (Stata) - stata

I have the following the code, which works well, but I want to also add lowess smoothing to the scatter and also keep the regional labels.
sepscatter avg_unemp log_avg_gdp, separate(region) addplot(lfit avg_unemp log_avg_gdp)
enter image description here
I found this option, but I want to keep all regions in one scatter, rather than a scatter plot per region.
twoway scatter avg_unemp log_avg_gdp, mcolor(*.6) ||
lfit avg_unemp log_avg_gdp ||
lowess avg_unemp log_avg_gdp ||, by(region)
Fixed the issue with Nick's suggestion:
sepscatter avg_unemp log_avg_gdp, separate(region) addplot(lowess avg_unemp log_avg_gdp if region=="Middle East & North Africa" | region=="Latin America & Caribbean" | region=="Europe & Central Asia" | region=="Sub-Saharan Africa" | region=="East Asia & Pacific" | region==" South Asia" | region=="North America ")

Related

Table for two-group mean-comparison tests with estpost

Since I am a Stata beginner, I don't know how to import my data, but I just wanted some help to understand my mistake.
I would like to create a table where the first column displays the mean characteritics of California, the second column the mean characteritics of all other states (unweighted by their population), and the last column reports the p-value of the differences in means. The variable California is a dummy variable where 1 equals to California and 0 equals to 38 others states.
Here is the result :
estpost ttest cigsale lnincome beer age15to24 retprice, by(California)
esttab using ta.rtf, cell("mu_1 mu_2 p") label ///
title(Mean characteristics of California and 38 control states) ///
collabels(none) unstack noobs nonumber mtitles("California" "2" "P value") ///
addnote("All variables are averaged from 1980 to 1988. Beer consumption is averaged from 1984 to 1988. GDP per capita is measured in 1997 dollars, retail prices are measured in cents, beer consumption is measured in gallons, and cigarette sales are measured in packs")
Result
The problem is that when I put mtitles ("California" "Average of 38 control states" "P value"), it only works for the column California as you can see in the picture. The two other columns do not have the titles "Average of 38 control states" and "P value". I have tried many commands but there is only a title for the California column.
Could you please help me figure out what is going on?
This is one model with three columns, so instead of mtitles you can use collabels.
collabels("California" "2" "P value")

How to Sort years in ascending or descending orders in power BI

I have my data like -
Course_Code
Source
Learning
2019-20
BAC
2019-20
SC_casting
2019-20
Rubber melt
2019-20
Learning
2018-19
Casting
2018-19
BAC
2018-19
Learning
2020-21
Learning
2020-21
Learning
2020-21
When I have created a chart I have taken values - "count of course code" (count distinct)
and in Axis - "Source"
my chart looks like
2020-21 -------------- 59
2018-19 ----------------------- 79
2019-20 ---------------------------- 104
the dashes are my bars of horizontal bar charts and the years are my Y axis
what I want is to sort the source like -
2020-21 -------------- 59
2019-20 ---------------------------- 104
2018-19 ----------------------- 79
Is there any way to do that in power BI?
I am new to power bi
since the data type of that column is text , it would sort the data as per text in either asc or desc format.
So in order for you to have the axis as per month order, create a new column of type integer (202012 etc) and sort the text column with this column.
Similar Refr:
Sort by full number in axis

DAX code to check multiple selected values in a Treemap

I am working on dynamically changing titles in PowerBI. I have Treemap which displays the population of 6 US states - 2 states from the east (NY, MA) and 3 from the west (CA, OR, WA).
The treemap looks like this -
A user can choose multiple states from a treemap by pressing ctrl and clicking on the square that represents the state.
When the user selects both the eastern states, I want the title to say "population in the east states" and similarly for the west too. Can this be done using DAX?
My title requirements -
If selected states are MA && NY then display "Population in the East States" as the title.
If selected states are CA && OR && WA then display "Population in the West States" as the title.
If only 1 state is selected then display the name of the state in the title.
I could do 3. Can someone please help me with 1 and 2?
Here's a measure that will do this.
Title =
SWITCH( TRUE(),
CONCATENATEX(VALUES(Table3[State]), Table3[State], ",") = "MA,NY",
"Population in the East States",
CONCATENATEX(VALUES(Table3[State]), Table3[State], ",") = "CA,OR,WA",
"Population in the West States",
HASONEVALUE(Table3[State]),
VALUES(Table3[State]),
"Population by State"
)
The VALUES function returns a list of the distinct values in the column specified.

Return stored results with svy and tab command in Stata

I would like to put column percentages into an excel file. The first step therefore would be to capture the percentages (or counts if not possible for percentages) into a matrix and then post the values into excel using putexcel. I can not use the matcell and matrow option with svy: tab so I attempted to check the stored results using e(name). The issue I am facing is how to capture the values from the following tabulation into a matrix:
webuse nhanes2b, clear
svyset psuid [pweight=finalwgt], strata(stratid)
svy: tabulate sex race , format(%11.3g) percent
--------------------------------------
1=male, | 1=white, 2=black, 3=other
2=female | White Black Other Total
----------+---------------------------
Male | 42.3 4.35 1.33 47.9
Female | 45.7 5.2 1.2 52.1
|
Total | 87.9 9.55 2.53 100
--------------------------------------
Key: cell percentages
I would like to put the values above in a matrix. I tried the following which worked:
mat pct = e(b)' * 100
matrix list pct
pct[6,1]
y1
p11 42.254909
p12 4.3497373
p13 1.3303765
p21 45.660537
p22 5.2008547
p23 1.2035865
But what I am interested in is the column percentages given by the following tabulation:
svy: tabulate sex race , format(%11.3g) col percent
--------------------------------------
1=male, | 1=white, 2=black, 3=other
2=female | White Black Other Total
----------+---------------------------
Male | 48.1 45.5 52.5 47.9
Female | 51.9 54.5 47.5 52.1
|
Total | 100 100 100 100
--------------------------------------
Key: column percentages
I tried this which did not return the desired values in the table above:
mat pct = e(b)' * 100
matrix list pct
pct[6,1]
y1
p11 42.254909
p12 4.3497373
p13 1.3303765
p21 45.660537
p22 5.2008547
p23 1.2035865
After checking through various stored objects using ereturn list I did not seem to find anything corresponding to column percentages.
How can I get the column percentages into a matrix?
easy peasy
ssc install estout
webuse nhanes2b, clear
estpost svy: tabulate race diabetes, row percent
esttab . using "C:/table.csv", b(2) se(2) scalars(F_Pear) nostar unstack mtitle(`e(colvar)')
see also here http://repec.org/bocode/e/estout/hlp_estpost.html#svy_tabulate

How do I use outreg2 to display value labels in its output?

Take this code
sysuse auto, clear
reg price mpg c.mpg#i.foreign
outreg2 using "example.txt", stats(coef) replace
This outputs
(1)
VARIABLES price
price
mpg -329.0***
0b.foreign#co.mpg 0
1.foreign#c.mpg 78.33**
Constant 12,596***
Observations 74
R-squared 0.289
Standard errors in parentheses
*** p<0.01, ** p<0.05, * p<0.1
Ideally, I'd like it to display the value labels, as is done in the console's regression output:
-------------------------------------------------------------------------------
price | Coef. Std. Err. t P>|t| [95% Conf. Interval]
--------------+----------------------------------------------------------------
mpg | -329.0368 61.46843 -5.35 0.000 -451.6014 -206.4723
|
foreign#c.mpg |
Foreign | 78.32918 29.78726 2.63 0.010 18.93508 137.7233
|
_cons | 12595.97 1235.936 10.19 0.000 10131.58 15060.35
-------------------------------------------------------------------------------
I don't need any of the other stats at the moment; I'm strictly including that last piece of output to show what I mean with the value labels. Searching through the documentation for outreg2 tells me how to display variable labels, but not value labels.
Also posted on Statalist.
As #Dimitriy points out, you can use estout, from SSC. An example:
sysuse auto, clear
reg price mpg c.mpg#i.foreign
estimates store m1, title(Model 1)
estout m1, label
You can add other statistics, stars and more. After installation (ssc install estout), read patiently help estout.
If you decode your variables and use xi, it will do the trick. Of course this solution assumes that you recode your variables, but if you want to stick with outreg2 is an easy solution.
sysuse auto, clear
set seed 1234
gen maxspeed = round(uniform()*3)+1
label define speed 1 "Light" 2 "Ridiculous" 3 "Ludicrous" 4 "Plaid"
label values maxspeed speed
decode maxspeed, gen(maxspeed_str)
decode foreign, gen(foreign_str)
xi: reg price mpg weight i.foreign_str*i.maxspeed_str
outreg2 using test, see text label
I used the example you asked in Statalist as it was your latest question.