stata

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

独自空忆成欢 提交于 2019-12-04 11:04:32
问题 This question already has answers here : Calculate group mean (or other summary stats) and assign to original data (4 answers) Closed last month . 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

about the equivalent command for forvalues

[亡魂溺海] 提交于 2019-12-04 07:06:24
问题 If we have multiple event outcomes as a long format like this (actual data contain many ids, this is a simplified data). data <- data.frame(id=c(rep(1, 4), rep(2, 3), rep(3, 3)), event=c(1, 1, 0, 0, 1, 1, 0, 1, 1, 0), eventcount=c(1, 2, 0, 0, 1, 2, 0, 1, 2, 0), firstevent=c(1, 0, 0, 0, 1, 0, 0, 1, 0, 0), time=c(100, 250, 150, 300, 240, 400, 150, 350, 700, 200) ) When I would like to pick up the event within a specific duration of time from the first event. In this case, I would like to detect

consistent barplot colors across graphs in Stata

穿精又带淫゛_ 提交于 2019-12-04 06:35:27
问题 I am outputting stacked bar plots in Stata, with each stacked bar ordered from bottom -> up : largest -> smallest Wins % per team. clear set obs 10 gen team = "yankees" if inlist(_n, 1, 6) replace team = "red sox" if inlist(_n, 2, 7) replace team = "mets" if inlist(_n, 3, 8) replace team = "nationals" if inlist(_n, 4, 9) replace team = "astros" if inlist(_n, 5, 10) gen wins = -10 + 20 * _n replace wins = wins[11 - _n] in 6/10 gen year = cond(_n <= 5, 2013, 2014) gen season = "regular" in 1/10

Mimic tabulate command from Stata in R

大城市里の小女人 提交于 2019-12-04 04:44:54
This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 7 years ago . Learn more . I'm trying to get a 2 way table in R similar to this one from Stata. I was trying to use CrossTable from gmodels package, but the table is not the same. Do you known how can this be done in R ? I hope at least to get the frequencies from when cursmoke1 == "Yes" & cursmoke2 == "No" and reversed In R I'm only getting totals from yes, no and NA. Here is the output: Stata . tabulate cursmoke1 cursmoke2, cell column miss row +-------------------+ | Key | |---------------

Is there a way to create Stata's _merge indicator variable with R's merge()?

北慕城南 提交于 2019-12-04 04:28:39
问题 Stata automatically creates a variable called "_merge" indicating the matched variables in both datasets after merge. Is there a way to get such variable generated by R's merge() function? 回答1: The possible values of _merge in Stata are (note merge can also have values 4 and 5) 1 master observation appeared in master only 2 using observation appeared in using only 3 match observation appeared in both In R , you can do that by entering the argument as either all=TRUE or all.x=TRUE or all.y

Equivalent function of R's “%in%” for Stata

狂风中的少年 提交于 2019-12-04 03:57:09
问题 Is there an equivalent function of "%in%" from R for Stata? 回答1: As already mentioned, it's hard to tell what you need from the question. inlist() might work, or it might not depending on the setting. I find that Stata's macro lists functions are invaluable. Store your list in a macro (local or global) and then a suite of useful commands are available: local list a b c d d e local search c local search_in_list : list search in list di `search_in_list' These can be calculated on the fly: if `:

Oaxaca Decomposition in R [closed]

故事扮演 提交于 2019-12-04 03:40:23
I would like to make a Oaxaca Decomposition in R. It is used in e.g. labor economics to distinguish explained variance versus unexplained variance, I believe. I have not been able to find a suitable solution in R, and I am rather reluctant to create one myself (I would probably mess it up). Anyway, the procedure is briefly explained here: http://en.wikipedia.org/wiki/Ronald_Oaxaca Stata is blessed with a rather good package for this, but Stata is not easily available to me. www.stata.com/meeting/5german/SINNING_stata_presentation.pdf Please note: I have also posted a message on R-help but it

sending code from vim to stata

半城伤御伤魂 提交于 2019-12-04 03:12:33
I have been using Vim to write Stata scripts in Windows for a while now at the university. I am learning R at the moment, and I want to switch completely to Linux as my OS (I've recently switched to Ubuntu on my laptop). R works fine with Vim in both Windows and Linux, however I still need to use Stata sometimes. In Windows I have been using a simple AutoIt script provided by a Stata user to send lines / the whole file to stata for evaluation. This script doesnt work in Linux. This is what the script looks like ; AutoIt v3 script to run a Stata do-file from an external text editor ; Version 3

Does Stata have any `try and catch` mechanism similar to Java?

筅森魡賤 提交于 2019-12-04 02:56:53
问题 I am writing a .do to check the existence of some variables in a number of .dta files as well as to check the existence of certain values for those variables. However, my code stops executing as it encounters an invalid variable name. I know I mix Java and Stata coding, and it is completely inappropriate, but is there any way I could do something like: try { su var1 local var1_mean=(mean)var1 local var1_min=(min)var1 local var1_max=(max)var1 ... } catch (NoSuchVariableException e) { System

Hausman type test in R

本小妞迷上赌 提交于 2019-12-03 21:35:08
I have been using " plm " package of R to do the analysis of panel data. One of the important test in this package for choosing between "fixed effect" or "random effect" model is called Hausman type . A similar test is also available for the Stata. The point here is that Stata requires fixed effect to be estimated first followed by random effect. However, I didn't see any such restriction in the "plm" package. So, I was wondering whether " plm " package has the default "fixed effect" first and then "random effect" second. For your reference, I mention below the steps in Stata and R that I