如果我们在行的开头加上"*",那么Stata应该忽略该行.
但我一次又一次地发现如果我不在评论行的末尾加分号,程序就会给我带来损坏的估计结果.
为什么是这样?
是不是Stata应该完全忽略整个评论线?
另外,一般来说,我何时应该而且不应该在行尾添加分号?
以下是我做错了什么?它默认情况下以浮点形式读入.为什么不count回归1?
clear
input stake
0.01
end
count if stake == 0.01
Run Code Online (Sandbox Code Playgroud) 如何按频率降序订购下表?
sysuse auto.dta, clear
replace make = substr(make,1, strpos(make," ")-2)
table make, c(N price mean price median price sd price min price max price) format(%9.2f) center
Run Code Online (Sandbox Code Playgroud)
第一次观察应该是buic或者oldN = 7.有没有办法按频率订购?
上面的代码也给出了错误too many stats().是否有一个允许更多列的替代程序?
我想用置信区间计算我的数据中的一组组的总结统计数据(例如年龄,性别).为此,我使用泊松分布中的蒙特卡罗模拟绘图值来获取数据中的每一行,然后折叠行以获得摘要.整个手术过程工作正常,如果模拟的结果(使用rclass返回标)只是一个值,但只要我尝试模拟多个结果(使用ereturn中的eclass矩阵),它是不工作(见下面的Stata代码).我收到错误消息:"表达式中的类型不匹配错误:e(A)".如何在没有更复杂的循环等的情况下模拟整个矢量甚至结果矩阵?
非常感谢!弗雷德
program bootPGW, eclass
use "C:\Users\649007\Desktop\Demetriq_PWG_edu.dta", replace
gen id=_n
sort id
gen N=_N
by id: gen DL2=floor(rpoisson(calung))
by id:gen D02=floor(rpoisson(D0))
by id:gen Dsmoking=floor(rpoisson(smoking))
by id:gen ML2=(DL2/numpyr)*1000
by id:gen AL2=(ML2-CPSIIrate)/ML2
by id:replace AL2=0 if AL2<0
by id:gen A02=1-exp(-PWGcoef*(ML2-CPSIIrate))
by id:gen A2=(AL2*DL2+A02*D02)/(DL2+D02)
gen Adeaths=totdeath*A2
collapse (sum) Adeaths=Adeaths totdeath=totdeath Dsmoking=Dsmoking, by(edu_3cat sex country year)
gen AF_PWG=Adeaths/totdeath
gen AF_simple=Dsmoking/totdeath
mkmat AF_PWG, matrix(A)
ereturn matrix A=A
end
simulate a=e(A), reps(1000) nodots seed(123): bootPGW
Run Code Online (Sandbox Code Playgroud) 我想重新定义Stata中的内置命令.比如说我想在summarize命令后添加缺失值的数量.当我为program被调用者创建ADO文件时summarize,Stata会自动使用内置程序而不是用户编写的程序.有没有办法改变这种行为?
我想从一些开始和结束日期创建虚拟变量,如果在范围内,则取值为 1。例如,从
id start end
1 01072014 05072014
1 05012014 06012015
Run Code Online (Sandbox Code Playgroud)
我想得到
id start end d_01012014 d_02012014 d_03012014 ... d_01052014 ... d_31122014
1 01012014 02012014 1 1 0 0 0
1 01052014 02052015 0 0 0 1 0
Run Code Online (Sandbox Code Playgroud)
这样我最终可以重塑我的数据,将所有观察结果排除在白天范围之外。我的想法是使用带有 stata 日期格式的循环,如下所示:
foreach i in *stataformat startdate*/*stataformat enddate* {
generate d_`i'=1 if `i'>=start & `i'<=end
}
Run Code Online (Sandbox Code Playgroud)
但是这种方法的问题是我的变量名称总是难以理解。那么您是建议另一种方法,还是知道如何将包含 stata 日期代码的变量重命名为“可理解”的名称?非常感谢!
我正在tex使用社区贡献的命令在文件中导出回归结果esttab:
esttab using reg.tex, nonumbers mtitles("1" "2" "3" "4" "5" "6" "7" "8" "9")
Run Code Online (Sandbox Code Playgroud)
该表包含九列。
我想让字体大小和列宽更小,以便在编译LaTeX.
当我使用时,有没有办法直接在 Stata 中执行此操作esttab?
我想用根据分类变量着色的点在 Stata 中制作散点图。
我发现这样做的唯一方法是在双向图的图层中编码颜色。
然而,对于这样一个简单的操作,这似乎是一个相当复杂的解决方案:
twoway (scatter latitud longitud if nougrups4 ==1, mcolor(black)) ///
(scatter latitud longitud if nougrups4 ==2, mcolor(blue)) ///
(scatter latitud longitud if nougrups4 ==3, mcolor(red)) ///
(scatter latitud longitud if nougrups4 ==4, mcolor(green))
Run Code Online (Sandbox Code Playgroud)
有没有更简单和自动的方法来做到这一点?
在这种情况下,分类变量nougrups4来自聚类分析。一般的解决方案会很好,但也是绘制集群的特定解决方案。
我想在我的 Stata 数据集中添加一个计数器(new_var-count-year)。
ID year new_var-count-year
1 2000 1
1 2001 2
1 2002 2
2 2001 1
2 2002 2
3 1999 1
3 2000 2
3 2001 3
3 2002 4
4 2005 1
5 2000 1
5 2001 2
Run Code Online (Sandbox Code Playgroud)
我知道这在大多数语言中都非常简单,但是:
if ID == ID[_n+1]{
new_var-count-year = new_var-count-year+1
}
else ...
Run Code Online (Sandbox Code Playgroud)
似乎在这里不起作用。
什么工作(非常糟糕的代码!)是:
gen freq_year = 1
bysort ID (year) : gen new_var-count-year = sum(freq_year)
Run Code Online (Sandbox Code Playgroud)