【发布时间】:2021-02-12 23:35:14
【问题描述】:
我下面的代码生成了附加的图表。但是,我正在尝试添加两个调整但没有运气。 1- 我想组织 Y 轴,所有行业的 11 月都在 12 月之前,而不是像当前图表中那样按哪个月有更多工作来排列。 2- 我还尝试在 Y 轴上添加标签,它只显示“Nov”和“Dec”,没有额外的文本,虽然 Stata 不会产生任何错误,但它不会改变图表。
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
我知道我可以在 Stata 中手动更改带有微小细节的图表,但如果可能的话,我更喜欢自动化该过程。
数据示例:
Example generated by -dataex-. To install: ssc install dataex
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"
当我使用 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
此外,这就是我创建变量以计算每个行业的工作数量的方式:
// 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)
【问题讨论】:
-
请提供数据示例。请阅读
help dataex和stata标签维基。 -
当心
(count)计数非缺失观察。每个行业和每个月的工作总数真的在 3 到 25 之间吗? -
我猜你想要
(sum)而不是(count)。为什么drop声明? -
但是您的图表显示 3 到 25 而您的数据没有。
标签: stata