stata

Mimic tabulate command from Stata in R

℡╲_俬逩灬. 提交于 2019-12-05 21:46:16
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 7 years ago . 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 .

Generate percent change between annual observations in Stata?

隐身守侯 提交于 2019-12-05 21:31:12
How do I use the gen or egen commands to generate the percent change between observations for different years in Stata? For example, I have observations for 1990 through 2010, each with a different value for expenditures, and I'm trying to generate a new observation with the percent change from 1990-1991, 1991-1992, etc. // Here's an example with another measure of growth: clear set obs 100 gen year = _n + 1959 gen expenditure = _n^(1/3) + runiform() line expenditure year, yti("Synthetic data example") // From Statalist : bys year: g expendituregrowth=100*(expenditure[_n]-expenditure[_n-1])

Oaxaca Decomposition in R [closed]

余生颓废 提交于 2019-12-05 18:49:48
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 8 months ago . 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

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

风流意气都作罢 提交于 2019-12-05 05:55:17
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? 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 a shortcut for this function in the Key Binding user file, where you put the function name in the command

Hausman type test in R

别来无恙 提交于 2019-12-05 02:08:46
问题 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

How to use RStudio to write a RMarkdown file with Stata commands?

一曲冷凌霜 提交于 2019-12-05 01:34:13
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 4 years ago . My problem is explained in the title. I've tried compiling a sample .Rmd I found here: http://www.ssc.wisc.edu/~hemken/Stataworkshops/Stata%20and%20R%20Markdown/ in addition to looking up various resources online to no avail. While my resource, Doug, was able to compile an RMarkdown, I am getting an error for the MWE below. The MWE is: --- title: "Stata and R Markdown (Windows)

Tabulate multiple variables with common prefix using a local macro

旧街凉风 提交于 2019-12-04 23:29:51
问题 I have a number of variables whose name begins with the prefix indoor . What comes after indoor is not numeric (that would make everything simpler). I would like a tabulation for each of these variables. My code is the following: local indoor indoor* foreach i of local indoor { tab `i' group, col freq exact chi2 } The problem is that indoor in the foreach command resolves to indoor* and not to the list of the indoor questions, as I hoped. For this reason, the tab command is followed by too

lme4::glmer vs. Stata's melogit command

社会主义新天地 提交于 2019-12-04 19:36:42
问题 Lately I have been trying to fit a lot of random effects models to relatively big datasets. Let’s say about 50,000 people (or more) observed at up to 25 time points. With such a large sample size, we include a lot of predictors that we’re adjusting for – maybe 50 or so fixed effects. I’m fitting the model to a binary outcome using lme4::glmer in R, with random intercepts for each subject. I can't go into specifics on the data, but the basic format of the glmer command I used was: fit <- glmer

Error in nchar() when reading in stata file in R on Mac

和自甴很熟 提交于 2019-12-04 19:20:05
I'm learning R and am simply trying to read in a stata data file but am getting the error below: X <- Stata.file(Stata_File) Error in nchar(varlabs) : invalid multibyte string 253 Multiple Mac users here are encountering this error with the program but it works fine on a PC. A google search of this error seems to say it has something to do with the R package but I can't find a solution. Any ideas? Thanks for your help!! The R code up to the error point is below: Root <- "/Users/Desktop/R_Training" PathIn <- paste(Root,"Data/Example_0",sep="/") # The 2007 Dominican Republic household member

R plm lag - what is the equivalent to L1.x in Stata?

允我心安 提交于 2019-12-04 14:09:26
问题 Using the plm package in R to fit a fixed-effects model, what is the correct syntax to add a lagged variable to the model? Similar to the 'L1.variable' command in Stata. Here is my attempt adding a lagged variable (this is a test model and it might not make sense): library(foreign) nlswork <- read.dta("http://www.stata-press.com/data/r11/nlswork.dta") pnlswork <- plm.data(nlswork, c('idcode', 'year')) ffe <- plm(ln_wage ~ ttl_exp+lag(wks_work,1) , model = 'within' , data = nlswork) summary