stata

Stata seemingly not actually rounding with round()

一笑奈何 提交于 2019-12-03 21:10:09
问题 Stata has a round() function. One can select the units it rounds to. I want to round an arbitrary floating point value to two decimal places using round(ArbitraryValue, 0.01) . Stata's display seems to understand this. But somehow the internal representation of round(ArbitraryValue, 0.01) still has the unrounded floating point value: . local LevelA = 99.98765432123321 . ttest mpg==20, level(`LevelA') <BR> level() can have at most two digits after the decimal point <BR> r(198); . local LevelB

Stata command line arguments in batch mode

若如初见. 提交于 2019-12-03 15:47:09
A helpful FAQ from Stata describes that arguments can be passed to do files. My do file looks like this: * program.do : Program to fetch information from main dataset args inname outname save `outname', emptyok // file to hold results insheet using `inname', comma clear names case // a bunch of processing save `outname', replace According to the FAQ, this script can be run using do filename.csv result.dta . When I run this command from within Stata, everything works fine. The program is long, however, so I want to run it in batch mode. Stata has another FAQ about batch mode. Combining the

Stata: Extracting values and save them as scalars (and more)

匿名 (未验证) 提交于 2019-12-03 09:14:57
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question is a follow-up question from Stata: replace, if, forvalues . Consider this data: set seed 123456 set obs 5000 g firmid = "firm" + string(_n) /* Observation (firm) id */ g nw = floor(100*runiform()) /* Number of workers in a firm */ g double lat = 39+runiform() /* Latitude in decimal degree of a firm */ g double lon = -76+runiform() /* Longitude in decimal degree of a firm */ The first 10 observations are: +--------------------------------------+ | firmid nw lat lon | |--------------------------------------| 1. | firm1 81 39

is there an equivalent to Stata's egen function? [duplicate]

百般思念 提交于 2019-12-03 06:45:46
This question already has answers here : Calculate group mean (or other summary stats) and assign to original data (4 answers) Stata has a very nice command, egen , which makes it easy to compute statistics over group of observation. For instance, it is possible to compute the max, the mean and the min for each group and add them as a variable in the detailed data set. The Stata command is one line of code : by group : egen max = max(x) I've never found the same command in R. summarise in the dplyr package makes it easy to compute statistics for each group but then I have to run a loop to

Extensive documentation on how to write a lexer for Pygments? [closed]

旧时模样 提交于 2019-12-03 06:31:40
I have a dictionary of Stata keywords and reasonable knowledge of Stata syntax. I would like to devote a few hours to turn it into a Stata lexer for Pygments . However, I cannot find enough documentation about the syntax of lexers and find myself unable to start coding the lexer. Could someone point out a good tutorial for writing new lexers for Pygments? I know about the Pygments API and the lexer development page , but honestly, these are not enough for someone like me with very limited knowledge of Python. My strategy so far has been to look for examples. I have found quite a few , e.g.

Convenient way to access variables label after importing Stata data with haven

情到浓时终转凉″ 提交于 2019-12-03 05:21:55
问题 In R, some packages (e.g. haven ) insert a label attributes to variables (e.g. haven ), which explains the substantive name of the variable. For example, gdppc may have the label GDP per capita . This is extremely useful, especially when importing data from Stata. However, I still struggle to know how to use this in my workflow. How to quickly browse the variable and the variable label? Right now I have to do attributes(df$var) , but this is hardly convenient to get a glimpse (a la names(df)

Loop over string variables in R

╄→гoц情女王★ 提交于 2019-12-03 05:11:07
问题 When programming in Stata I often find myself using the loop index in the programming. For example, I'll loop over a list of the variables nominalprice and realprice: local list = "nominalprice realprice" foreach i of local list { summarize `i' twoway (scatter `i' time) graph export "C:\TimePlot-`i'.png" } This will plot the time series of nominal and real prices and export one graph called TimePlot-nominalprice.png and another called TimePlot-realprice.png. In R the method I've come up with

Read Stata 13 file in R

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Is there a way to read a Stata 13 file in R? I tried the following, and I got the following error: > library ( foreign ) > data = read . dta ( "TEAdataSTATA.dta" ) Error in read . dta ( "TEAdataSTATA.dta" ) : not a Stata version 5 - 12 . dta file Could someone point out if there is a way to fix this? 回答1: If you have Stata 13, then you can load it there and save it as a Stata 12 format using the command saveold (see help saveold ). Afterwards, take it to R. If you have, Stata 10 - 12, you can use the user-written command use13 ,

stata odbc sqlfile

匿名 (未验证) 提交于 2019-12-03 02:36:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to load data from database (either MS Access or SQL server) using odbc sqlfile it seems that the code is running with any error but I am not getting data. I am using the following code odbc sqlfile("sqlcode.sql"),dsn("mysqlodbcdata") . Note that sqlcode.sql contains just sql statement with SELECT . The thing is that the same sql code is giving data with odbc load,exec(sqlstmt) dsn("mysqlodbcdata") . Can anyone suggest how can I use odbc sqlfile to import data? This would be a great help for me. Thanks Joy 回答1: sqlfile

Stata drops variables that “predicts failure perfeclty” even though the correlation between the variables isn&#039;t 1 or -1?

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am running a logit regression on some data. My dependent variable is binary as are all but one of my independent variables. When I run my regression, stata drops many of my independent variables and gives the error: "variable name" != 0 predicts failure perfectly "variable name" dropped and "a number" obs not used I know for a fact that some of the variables dropped don't predict failure perfectly. In other words, the dependent variables can take on the value 1 for either the value 1 or 0 of the independent variable. Why is this happening