编辑hbar图(Stata)
下面的代码生成所附的图表。然而,我试图增加两个调整,但没有运气。 1-我想组织Y轴,所有行业的11月都在12月之前,而不是按照当前图表中哪个月有更多的工作安排。 2-我还尝试在Y轴上添加标签,在Y轴上只显示“Nov”和“Dec”,而不显示额外的文本,虽然Stata不会产生任何错误,但它不会更改图形编辑hbar图(Stata),stata,Stata,下面的代码生成所附的图表。然而,我试图增加两个调整,但没有运气。 1-我想组织Y轴,所有行业的11月都在12月之前,而不是按照当前图表中哪个月有更多的工作安排。 2-我还尝试在Y轴上添加标签,在Y轴上只显示“Nov”和“Dec”,而不显示额外的文本,虽然Stata不会产生任何错误,但它不会更改图形 preserve drop if total_jobs_industry<15 graph hbar (count) total_jobs_industry, over(month) over(
preserve
drop if total_jobs_industry<15
graph hbar (count) total_jobs_industry, over(month) over(industry, sort(1)) subtitle("Jobs by Industry and month", span)
restore
当我用sum而不是count运行时,我得到了下图:
preserve
drop if total_jobs_industry<15
graph hbar (sum) total_jobs_industry, over(month) over(industry, sort(1)) subtitle("Jobs by Industry and month", span)
restore
这是一个非常令人费解的问题。以下原因列表不完整
(count)
对您的数据有意义。如上所述,它统计未丢失的值,但您的关键变量似乎是total\u count\u industry
。另一方面,使用不同的(sum)
,观察的数量似乎会混淆不同类型的计算
D
在N
之前排序这一事实至关重要。这就是12月份在1月份之前排序的原因,与行业价值排序无关,这只影响酒吧组的排序。您没有使用Stata的日期变量功能
graph hbar
的一个限制,它忽略了时间变量显示格式,所以我使用了值标签来确保Nov
和Dec
按照您希望的顺序排序
clear
input float total_jobs_industry str39 industry str8 month
11 "Architectural & Engineering Services" "Nov_2020"
11 "Architectural & Engineering Services" "Nov_2020"
11 "Architectural & Engineering Services" "Dec_2020"
11 "Architectural & Engineering Services" "Dec_2020"
11 "Architectural & Engineering Services" "Nov_2020"
11 "Architectural & Engineering Services" "Dec_2020"
11 "Architectural & Engineering Services" "Dec_2020"
11 "Architectural & Engineering Services" "Nov_2020"
38 "Computer Hardware & Software" "Dec_2020"
12 "Consulting" "Dec_2020"
63 "" "Dec_2020"
32 "IT Services" "Dec_2020"
32 "IT Services" "Nov_2020"
38 "Computer Hardware & Software" "Nov_2020"
12 "Aerospace & Defense" "Nov_2020"
12 "Accounting" "Nov_2020"
12 "Accounting" "Dec_2020"
end
duplicates drop
gen mdate = monthly(month, "MY")
levelsof mdate, local(months)
tokenize "`c(Mons)'"
foreach m of local months {
local month = month(dofm(`m'))
label def mdate `m' "``month''", modify
}
label val mdate mdate
set scheme s1color
graph hbar (asis) total_jobs_industry, over(mdate) over(industry, sort(1) descending)
请提供数据示例。请阅读
help dataex
和stata
标签wiki。注意(计数)
计数未缺失的观察值。每个行业和月份的总工作岗位真的在3到25个之间吗?我猜你想要的是(sum)
而不是(count)
。为什么要使用drop
语句?但是您的图表显示3到25,而您的数据却没有。
// The variable id contains observation number running from 1 to X and nt is the total number of observations
generate id = _n
generate nt = _N
// Sorting by inudstry. Now n1 is the observation number within each Industry group and total_jobs_industry is the total number of observations for each Industry group.
sort industry
by industry: generate n1 = _n
by industry: generate total_jobs_industry = _N
order total_jobs_industry, a(industry)
clear
input float total_jobs_industry str39 industry str8 month
11 "Architectural & Engineering Services" "Nov_2020"
11 "Architectural & Engineering Services" "Nov_2020"
11 "Architectural & Engineering Services" "Dec_2020"
11 "Architectural & Engineering Services" "Dec_2020"
11 "Architectural & Engineering Services" "Nov_2020"
11 "Architectural & Engineering Services" "Dec_2020"
11 "Architectural & Engineering Services" "Dec_2020"
11 "Architectural & Engineering Services" "Nov_2020"
38 "Computer Hardware & Software" "Dec_2020"
12 "Consulting" "Dec_2020"
63 "" "Dec_2020"
32 "IT Services" "Dec_2020"
32 "IT Services" "Nov_2020"
38 "Computer Hardware & Software" "Nov_2020"
12 "Aerospace & Defense" "Nov_2020"
12 "Accounting" "Nov_2020"
12 "Accounting" "Dec_2020"
end
duplicates drop
gen mdate = monthly(month, "MY")
levelsof mdate, local(months)
tokenize "`c(Mons)'"
foreach m of local months {
local month = month(dofm(`m'))
label def mdate `m' "``month''", modify
}
label val mdate mdate
set scheme s1color
graph hbar (asis) total_jobs_industry, over(mdate) over(industry, sort(1) descending)