编辑hbar图(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(

下面的代码生成所附的图表。然而,我试图增加两个调整,但没有运气。 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(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)
    ,观察的数量似乎会混淆不同类型的计算

  • 示例数据中似乎存在重复的观察结果

  • 您声明您“还尝试向Y轴添加标签,其中仅显示“Nov”和“Dec”,但代码中没有显示任何此类注释尝试

  • 您希望2020年11月在2020年12月之前排序,这不会发生,因为就Stata而言,它只是一个字符串变量,因此
    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)