stata

Calculate industry concentration based on four biggest numbers

北城以北 提交于 2020-01-15 09:10:35
问题 I am trying to find the four biggest numbers of a variable in Stata, as I want to calculate the industry concentration of different groups based on sales. I have firms sales from multiple years and the firms belong to different groups based on industries and countries. Thus, I would like to find: industry concentration = (4 biggest sales-values of a year of one industry-&-country-group) / sum of all sales for one year of the industry-&-country-group) I have about 10000 firms for about 10

Comparing elements of two different local macros

三世轮回 提交于 2020-01-15 07:29:07
问题 I have a local macro called peer_list that contains 280 distinct elements, all of which are strings. I also have another local macro called used_list that contains a subset of the elements contained in the local peer_list . For each element in peer_list I would like to test whether that element is in the local used_list . If the element exists in used_list I would like to discard it, otherwise I would like to execute another set of conditions. I have tried to use the following code but it

Combined Pearson/Spearman rank correlation matrix with significance stars in Stata

我只是一个虾纸丫 提交于 2020-01-15 07:11:34
问题 I want to calculate a correlation matrix, where the lower triangle consists of Pearson and the upper triangle consists of Spearman rank correlation coefficients. I am using corr and spearman , which works fine. But with corr I cannot get the significance (p-value or stars and so on). So I tried pwcorr, list which gives me the exact results but with significance. Using this "new combination" I cannot create the matrix as with corr . //Get Pearson Matrix corr var1 var2 var3 matrix R = r(C) /

In Sublime Text 3, can I send a selection of a do file to Stata?

六月ゝ 毕业季﹏ 提交于 2020-01-13 09:54:29
问题 This SO question led me to try Sublime Text 3 as a replacement for Stata's do file editor on Linux (full instructions here). Syntax highlighting works and a Ctrl+B shortcut sends the whole do file to Stata. Is there a way to send only a selection of lines to Stata? 回答1: Yes you can. First you need to find the name of the python function that does it. For the SublimeStata Enhanced package , it corresponds to the function text_2_stataCommand in the file text_2_stata.py. Second, you need to add

In Sublime Text 3, can I send a selection of a do file to Stata?

旧城冷巷雨未停 提交于 2020-01-13 09:54:25
问题 This SO question led me to try Sublime Text 3 as a replacement for Stata's do file editor on Linux (full instructions here). Syntax highlighting works and a Ctrl+B shortcut sends the whole do file to Stata. Is there a way to send only a selection of lines to Stata? 回答1: Yes you can. First you need to find the name of the python function that does it. For the SublimeStata Enhanced package , it corresponds to the function text_2_stataCommand in the file text_2_stata.py. Second, you need to add

In Sublime Text 3, can I send a selection of a do file to Stata?

天大地大妈咪最大 提交于 2020-01-13 09:54:05
问题 This SO question led me to try Sublime Text 3 as a replacement for Stata's do file editor on Linux (full instructions here). Syntax highlighting works and a Ctrl+B shortcut sends the whole do file to Stata. Is there a way to send only a selection of lines to Stata? 回答1: Yes you can. First you need to find the name of the python function that does it. For the SublimeStata Enhanced package , it corresponds to the function text_2_stataCommand in the file text_2_stata.py. Second, you need to add

How to count the number of observations in R like Stata command count

匆匆过客 提交于 2020-01-12 05:33:03
问题 aaa<- data.frame(sex=c(1,1,2,2,1,1), group1=c(1,2,1,2,2,2),group2=c("A","B","A","B","A","B")) stata command: count if sex==1 & group1==2 count if sex==1 & group2=="A" count counts the number of observations that satisfy the specified conditions. If no conditions are specified, count displays the number of observations in the data. How to count in R? Thank you. 回答1: The with function will let you use shorthand column references and sum will count TRUE results from the expression(s). sum(with

How to count the number of observations in R like Stata command count

强颜欢笑 提交于 2020-01-12 05:32:06
问题 aaa<- data.frame(sex=c(1,1,2,2,1,1), group1=c(1,2,1,2,2,2),group2=c("A","B","A","B","A","B")) stata command: count if sex==1 & group1==2 count if sex==1 & group2=="A" count counts the number of observations that satisfy the specified conditions. If no conditions are specified, count displays the number of observations in the data. How to count in R? Thank you. 回答1: The with function will let you use shorthand column references and sum will count TRUE results from the expression(s). sum(with

Convert .CSV files to .DTA files in Python

依然范特西╮ 提交于 2020-01-11 11:58:12
问题 I'm looking to automate the process of converting many .CSV files into .DTA files via Python. .DTA files is the filetype that is handled by the Stata Statistics language. I have not been able to find a way to go about doing this, however. The R language has write(.dta) which allows a dataFrame in R to be converted to a .dta file, and there is a port to the R language from Python via RPy, but I can't figure out how to use RPy to access the write(.dta) function in R. Any ideas? 回答1: You need

Different Robust Standard Errors of Logit Regression in Stata and R

雨燕双飞 提交于 2020-01-09 06:36:12
问题 I am trying to replicate a logit regression from Stata to R. In Stata I use the option "robust" to have the robust standard error (heteroscedasticity-consistent standard error). I am able to replicate the exactly same coefficients from Stata, but I am not able to have the same robust standard error with the package "sandwich". I have tried some OLS linear regression examples; it seems like the sandwich estimators of R and Stata give me the same robust standard error for OLS. Does anybody know