人口普查中的 X12 季节性调整计划,输入文件扩展名问题
我下载了位于此处的 X12 季节性调整计划:http://www.census.gov /srd/www/x12a/x12downv03_pc.html
我按照设置进行操作并得到了正确的设置。当我选择要输入的文件时,我有四个要导入的文件扩展名选项,分别是“.spc”、“.mta”、“.dta”和“.”。
问题是我在 Excel 中有数据,并且通过搜索引擎进行了广泛搜索,但我确实无法找到一种方法将 Excel 中的数据转换为其中一种格式,以便我可以对数据进行季节性调整。谢谢
添加:转换为 dta 文件后(由于下面留下的注释,使用 R),看起来该程序也让您将其也转换为 .spc 文件。有人知道如何做到这一点吗?谢谢
I downloaded the X12 seasonal adjustment program located here: http://www.census.gov/srd/www/x12a/x12downv03_pc.html
I followed the setup and got the setting correct. When I go to select a file to input I have four options for file extensions to import which are ".spc" ".mta" ".dta" and "."
The problem is that I have data in excel and I have searched extensively through search engines and I do cannot figure out a way to get data from excel into one of these formats so I can do a seasonal adjustment on my data. Thanks
ADDED: After converting to a dta file (using R thanks to the comments left below) it looks like the program makes you convert it also to a .spc file as well. Anyone have a lead on how to do this? thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的第一反应是:
(1) 将 Excel 中的数据导出为 csv 等简单格式。
(2) 将数据导入R
(3)使用R库“foreign”将数据导出为.dta格式。
因此,对于包含以下内容的文件“test.csv”:
您可以执行以下操作来生成“test.dta”:
瞧,.dta 格式的数据。这对你所拥有的有用吗?
My first reaction is to:
(1) export the data from excel in something simple like csv.
(2) import that data into R
(3) use the R library "foreign" to export the data in .dta format.
So with the file "test.csv" containing:
you could do the following to produce "test.dta":
Voila, data in .dta format. Would this work for what you have?
我只使用过 X12 的命令行版本,但听起来您可能正在使用 Windows 界面?如果是这样,以下内容可能不完全准确,但应该足够接近(我希望!)。
您引用的 .dta 和 .mta 文件只是元文件,其中包含要处理的规范文件或数据文件的文本列表;特别是X12 使用的 .dta 文件不是 Stata 数据格式文件,就像 Nathan 基于 R 的答案生成的文件一样。在您能够熟练地使用该软件来调整单个时间序列之前,最好忽略使用图元文件。
您可以以制表符分隔的变量格式(年月/季度值)导出数据,不带标题,并将其用作数据文件。您还可以使用由空格、制表符或换行符分隔的简单数据值列表,然后告诉 X12ARIMA .spc 文件中系列的开始和结束日期。
.spc 文件不包含输入数据,它是一个规范文件,告诉 X12 在哪里可以找到数据文件以及您希望如何处理这些数据 - 您必须自己编写它们或在 Win X 中创建它们 - 12.
理想情况下,您应该为每个要调整的时间序列编写一个单独的 .spc 文件;虽然您可以编写一个 .spc 文件来调用许多 X12 的自动选择和识别过程,但将过程视为黑匣子通常不是一个好主意,并且通常需要在 .spc 中进行一些手动干预才能获得良好的结果。质量调整(如果涉及季节性休息,则至关重要)。我发现从一个适合您的计算环境的相当通用的骨架 .spc 文件开始,然后根据每个系列的情况进行调整是很有帮助的。
如果您确实想使用单个 .spc 文件来调整多个系列,那么您可以在 .dta 文件中提供数据文件列表和单个 .spc 文件指示 X12ARIMA 如何调整它们,但请注意确保这是适合您的数据!
该网站上的“在您的 PC 上开始使用 X-12-ARIMA 输入文件”文档可能是开始阅读的好地方,但您最终可能需要查阅完整的参考文档(特别是第 3 章和第 7 章) )也是如此。
编辑后记:
英国国家统计局在线提供了 X12ARIMA 季节性调整指南草案
此处此处(archive.org),值得一看。它比人口普查局的文件更容易完成。I've only ever used the command-line version of X12, but it sounds like you may be using the windows interface instead? If so the following might not be entirely accurate, but it should be close enough (I hope!).
The .dta and .mta files you refer to are just metafiles containing text lists of either spec files or data files to be processed; in particular the .dta files X12 uses are NOT Stata data format files like those produced by Nathan's R-based answer. It's probably best to ignore using metafiles until you are comfortable enough using the software to adjust a single time series.
You can export your data in tab separated variable format (year month/quarter value) without headings and use that as your data file. You can also use a simple list of data values separated by spaces, tabs, or newlines and then tell X12ARIMA what the start and end dates of the series are in the .spc file.
The .spc file doesn't contain the input data, it's a specification file telling X12 where to find the data file and how you want those data to be processed -- you'll have to write them yourself or create them in Win X-12.
Ideally you should write a separate .spc file for each time series to be adjusted; while you can write a .spc file which invokes many of X12's autoselection and identification procedures, it's usually not a good idea to treat the process as a black box, and a bit of manual intervention in the .spc is often necessary to get a good quality adjustment (and essential if there's a seasonal break involved). I find it helpful to start with a fairly generic skeleton .spc file suitable for your computing environment to begin with and then tweak it from there as appropriate for each series.
If you really want to use a single .spc file to adjust multiple series, then you can provide a list of data files in a .dta file and a single .spc file instructing X12ARIMA how to adjust them, but take care to ensure this is appropriate for your data!
The "Getting started with X-12-ARIMA input files on your PC" document on that site is probably a good place to start reading, but you'll probably end up having to consult the complete reference documentation (in particular Chapters 3 and 7) as well.
Edit postscript:
The UK Office for National Statistics have a draft of their guide to seasonal adjustment with X12ARIMA available online
herehere (archive.org), and is worth a look. It's a good bit easier to work through than the Census Bureau documentation.Ryan,
这并不优雅,但可能对你有用。在此示例中,我尝试复制人口普查文档中示例 3.2 中的规范文件。
将数据连接成一个文本字符串,然后使用“SAVE AS”命令下的 MS-DOS (TXT) 格式保存该单个文本字符串。要创建文本字符串,请首先在列标题上方插入两个单元格,然后在第二个单元格中键入以下文本。
接下来,在列标题中的文本前后插入双引号,如下所示:
在最后一个数据行的正下方,插入列出型号规格的文本行,如下所示:
因此,您应该具有如下所示的内容:
对于下一个说明,我假设文本 *系列{标题=
* 出现在单元格 A2 中,而单元格 B1 为空。在单元格 B2 中,插入以下内容:
然后将此公式复制到列中的每个单元格中,以将 A 列中的所有文本连接到 B 列末尾的单个单元格中。最后,将最终单元格复制到新电子表格的使用“粘贴特殊/值”的单元格 A1,并使用“另存为”保存此电子表格:*TXT(MS-DOS),但将扩展名更改为“.spc”。
祝你好运(从我读到的一点人口普查文档来看 - 你会需要它)。
Ryan,
This is not elegant, but it might work for you. In this example I'm trying to replicate the spec file from the Example 3.2 in the Census documentation.
Concatentate the data into one text string, then save this single text string using the MS-DOS (TXT) format under the SAVE AS command. To make the text string, first insert two cells above your column header and in the second one type the following text into it.
Next, insert double quotation marks before and after the text in your column header, like this:
Directly below the last data row, insert rows of texts that list the model specifications, like the following:
So you should have something like the following:
For the next instructions I am assuming that the text *series{title=
* appears in cell A2 and that cell B1 is empty. In cell B2, insert the following:
Then copy this formula into every cell down the column to concatentate all of the text in column A into a single cell at the end of column B. Finally, copy the final cell to a new spreadsheet's cell A1 using PASTE SPECIAL/VALUE, and save this spreadsheet using SAVE AS: *TXT(MS-DOS), but change the extension to ".spc".
Good luck (and from the little I read of the Census documentation - you'll need it).