stata

Rounding summary statistics exported to LaTeX using esttab

会有一股神秘感。 提交于 2020-01-30 08:56:24
问题 I want to export summary statistics table (mean, median, min, max, sd) to LaTeX using the community-contributed command esttab but rounding the reported statistics to two decimals. Below is my Stata code: eststo sumstats1: quietly estpost sum var1 var2 var3, detail esttab sumstats1, cells("mean p50 min max sd") nonumbers label esttab sumstats1 using "$repodir/output/tables/sumstats.tex", booktabs /// label nonumbers cells("mean p50 min max sd") replace My results show summary statistics but

Stacking variables one below the other

廉价感情. 提交于 2020-01-30 07:26:10
问题 I have the following variables in my Stata dataset: clear input BGJTH98 GJKE54 SDKA12 JLTH65 VCNH58 2907 199 641 202 487 2908 199 641 202 487 2909 199 641 202 487 2910 199 641 202 487 2911 199 641 202 487 2912 199 641 202 487 2913 199 641 202 487 2914 199 641 202 487 2915 199 641 206 487 2916 199 641 202 487 2917 199 641 202 487 2918 199 641 202 487 2919 199 641 202 487 2920 204 641 202 487 2921 204 641 202 487 2922 204 641 202 487 2923 204 641 202 487 2924 204 641 202 487 2925 204 641 202

Stacking variables one below the other

本秂侑毒 提交于 2020-01-30 07:25:11
问题 I have the following variables in my Stata dataset: clear input BGJTH98 GJKE54 SDKA12 JLTH65 VCNH58 2907 199 641 202 487 2908 199 641 202 487 2909 199 641 202 487 2910 199 641 202 487 2911 199 641 202 487 2912 199 641 202 487 2913 199 641 202 487 2914 199 641 202 487 2915 199 641 206 487 2916 199 641 202 487 2917 199 641 202 487 2918 199 641 202 487 2919 199 641 202 487 2920 204 641 202 487 2921 204 641 202 487 2922 204 641 202 487 2923 204 641 202 487 2924 204 641 202 487 2925 204 641 202

How to export Spearman correlations

为君一笑 提交于 2020-01-28 10:08:11
问题 I am trying to export the Spearman correlation matrix into an rtf or Excel file using estpost and the community-contributed command esttab . However, I am getting the following error: invalid subcommand r(198); Below is my code: estpost spearman varlists, matrix stats(rho p) star(.05) estimates store cl esttab * using corrtable.rtf, b(%6.3f) label alignment(l) unstack not noobs compress replace 回答1: The spearman command does not work with estpost , which is why Stata complains. The following

Conditioning Stata dataset on past values of variables

偶尔善良 提交于 2020-01-25 10:58:08
问题 I have a problem in conditioning the dataset I have on Stata. Basically I want to condition the presence in the dataset -within a certain group- of an observation for which a certain action is performed (as indicated by a variable) on the past values of another variable. So let's suppose I have the following obs | id | action1 | action2 | year 1 | 1 | 1 | 0 | 2000 2 | 1 | 0 | 1 | 2001 3 | 1 | 0 | 1 | 2002 4 | 1 | 0 | 1 | 2002 5 | 1 | 0 | 1 | 2003 6 | 2 | 1 | 0 | 2000 7 | 2 | 1 | 0 | 2001 8 |

replace missing value based on linear prediction of nearby cells

情到浓时终转凉″ 提交于 2020-01-24 19:39:12
问题 I have a dataset ( tsset ) that has observations in some years but not others: year x 1990 600 1991 . 1992 . 1993 . 1994 . 1995 1100 1996 . 1997 . 1998 1700 Suppose I am willing to make the assumption that every missing observation between two non-missing years (say 1990 and 1995 for example) can be imputed by a linear prediction between the said non-missing years, which makes the data like year x 1990 600 1991 [700] 1992 [800] 1993 [900] 1994 [1000] 1995 1100 1996 [1300] 1997 [1500] 1998

Save .dta files in python

谁说胖子不能爱 提交于 2020-01-20 17:53:06
问题 I'm wondering if anyone knows a Python package that allows you to save numpy arrays/recarrays in the .dta format of the statistical data analysis software Stata. This would really speed up a few steps in a system I have. 回答1: pandas DataFrame objects now have a "to_stata" method. So you can do for instance import pandas as pd df = pd.read_stata('my_data_in.dta') df.to_stata('my_data_out.dta') DISCLAIMER: the first step is quite slow (in my test, around 1 minute for reading a 51 MB dta - also

How to use a forval loop and take into account one exception?

断了今生、忘了曾经 提交于 2020-01-16 18:15:09
问题 I have 900 files that include 1,000 variables named v1 – v1000 and 1 file that includes 43 variables named v1 – v43. My code in Stata initially opens each file using a foreach loop that imports the files while erasing the first line for each file (not shown here). Then, I use this nested forval loop to rename variables: forval j = 1/1000 { local varname = strtoname(v`j'[1]) rename v`j' x`varname' } This code doesn’t work well because my last file doesn’t have the variables named v44 – v1000.

Add number of second level groups in esttab after mixed

痴心易碎 提交于 2020-01-16 00:42:14
问题 I am running multilevel random intercept models with the mixed command in Stata 14 SE. I want to export the results with the community-contributed command esttab but I cannot figure out how to add the number of second level groups to the output, which in my case it's rather important. More specifically, I cannot seem to find the number of groups if I run ereturn list , even though Stata displays it after the mixed command. Here is an example of the code: mixed defect c.cenretrosoc c.centrust

Generating and ordering a variable simultaneously

风格不统一 提交于 2020-01-15 11:55:07
问题 I would like to avoid re-ordering the data to place the generated variable in the first column: sysuse auto, clear gen random = runiform() order random Is it possible to generate a variable and at the same time order it? The idea is to be able to directly observe the generated variable when I browse the data in the editor, which is not easy when I have several variables. 回答1: You can use the before() option: sysuse auto, clear generate random = runiform(), before(make) You can also further