0

我正在尝试将工作报告的变量制成表格,以显示当前在该领域的调查的市政府完成率。每周都会下载一个数据集,显示迄今为止的所有响应,我需要生成一个表格,显示我们样本中所有城市的频率,即使它们为零。使用缺失选项不起作用,因为生成报告的数据集无法告诉 stata 城市的整体样本是什么。

有没有办法让它根据整个样本中的值列表将不在数据集中的值显示为零?我精通 R,所以如果有人对如何在 R 中执行此操作有建议,那也很好。

到目前为止,这是我的代码:

将字符串变量转换为带有值标签的数值变量

    encode municipality_name, gen(municipality)

将市政当局完成的调查导出到 .doc 文件

    asdoc tab municipality, mis
4

1 回答 1

3

来自 SSC的社区贡献命令fre允许将数据集中未出现的标记值列表为具有零频率。这是一个例子:

. sysuse auto, clear
(1978 Automobile Data)

. fre foreign

foreign -- Car type
----------------------------------------------------------------
                   |      Freq.    Percent      Valid       Cum.
-------------------+--------------------------------------------
Valid   0 Domestic |         52      70.27      70.27      70.27
        1 Foreign  |         22      29.73      29.73     100.00
        Total      |         74     100.00     100.00           
----------------------------------------------------------------

. label def origin 42 "Extraterrestrial", add

. fre foreign

foreign -- Car type
----------------------------------------------------------------
                   |      Freq.    Percent      Valid       Cum.
-------------------+--------------------------------------------
Valid   0 Domestic |         52      70.27      70.27      70.27
        1 Foreign  |         22      29.73      29.73     100.00
        Total      |         74     100.00     100.00           
----------------------------------------------------------------

. fre foreign, includelabeled

foreign -- Car type
-------------------------------------------------------------------------
                            |      Freq.    Percent      Valid       Cum.
----------------------------+--------------------------------------------
Valid   0  Domestic         |         52      70.27      70.27      70.27
        1  Foreign          |         22      29.73      29.73     100.00
        42 Extraterrestrial |          0       0.00       0.00     100.00
        Total               |         74     100.00     100.00           
-------------------------------------------------------------------------

. ssc desc fre

--------------------------------------------------------------------------------------------------------
package fre from http://fmwww.bc.edu/repec/bocode/f
--------------------------------------------------------------------------------------------------------

TITLE
      'FRE': module to display one-way frequency table

DESCRIPTION/AUTHOR(S)

        fre displays, for each specified variable, a univariate
      frequency table containing counts, percent, and cumulative
      percent. Variables may be string or numeric. Labels, in full
      length, and values are printed. By default, fre only tabulates
      the smallest and largest 10 values (along with all missing
      values), but this can be changed. Furthermore,  values with zero
      observed frequency may be included in the  tables. The default
      for fre is to display the frequency  tables in the results
      window. Alternatively, the tables may be written to a file on
      disk, either tab-delimited or  LaTeX-formatted.

      KW: data management
      KW: frequencies
      KW: frequency table
      KW: tabulation

      Requires: Stata version 9.2

      Distribution-Date: 20150603

      Author: Ben Jann, University of Bern
      Support: email jann@soz.unibe.ch


INSTALLATION FILES                                  (type net install fre)
      fre.ado
      fre.hlp

ANCILLARY FILES                                     (type net get fre)
      fre.zip
--------------------------------------------------------------------------------------------------------
(type ssc install fre to install)
于 2020-01-23T09:21:30.313 回答