stata

Paths to do-file in Stata

一世执手 提交于 2019-12-18 04:23:18
问题 Would it be possible, when I launch a do-file to recover the path of the do-file as a variable? I'm sharing a project with a co-author (via Dropbox). The structure of the folders (data, logs, etc.) is therefore the same on both sides. But the folders are situated differented on my coauthor's filesystem and mine. It would therefore be helpful for us to write do-file that are agnostic about the path of the folders, etc. We would like the path to our projects not to be hard-coded. Thank you! 回答1

Using if qualifier with egen in Stata

时光怂恿深爱的人放手 提交于 2019-12-17 19:39:14
问题 I'm using Stata, and I'm trying to compute the average price of firms' rivals in a market. I have data that looks like: Market Firm Price ---------------------- 1 1 100 1 2 150 1 3 125 2 1 50 2 2 100 2 3 75 3 1 100 3 2 200 3 3 200 And I'm trying to compute the average price of each firm's rivals, so I want to generate a new field that is the average values of the other firms in a market. It would look like: Market Firm Price AvRivalPrice ------------------------------------ 1 1 100 137.2 1 2

Mutate multiple columns in a dataframe

主宰稳场 提交于 2019-12-17 18:23:01
问题 I have a data set that looks like this. bankname bankid year totass cash bond loans Bank A 1 1881 244789 7250 20218 29513 Bank B 2 1881 195755 10243 185151 2800 Bank C 3 1881 107736 13357 177612 NA Bank D 4 1881 170600 35000 20000 5000 Bank E 5 1881 3200000 351266 314012 NA and I want to compute some ratios based on bank balance sheets. and I want the dataset to look like this bankname bankid year totass cash bond loans CashtoAsset BondtoAsset LoanstoAsset Bank A 1 1881 2447890 7250 202100

Pandas read_stata() with large .dta files

老子叫甜甜 提交于 2019-12-17 16:10:14
问题 I am working with a Stata .dta file that is around 3.3 gigabytes, so it is large but not excessively large. I am interested in using IPython and tried to import the .dta file using Pandas but something wonky is going on. My box has 32 gigabytes of RAM and attempting to load the .dta file results in all the RAM being used (after ~30 minutes) and my computer to stall out. This doesn't 'feel' right in that I am able to open the file in R using read.dta() from the foreign package no problem, and

Pandas read_stata() with large .dta files

旧城冷巷雨未停 提交于 2019-12-17 16:09:19
问题 I am working with a Stata .dta file that is around 3.3 gigabytes, so it is large but not excessively large. I am interested in using IPython and tried to import the .dta file using Pandas but something wonky is going on. My box has 32 gigabytes of RAM and attempting to load the .dta file results in all the RAM being used (after ~30 minutes) and my computer to stall out. This doesn't 'feel' right in that I am able to open the file in R using read.dta() from the foreign package no problem, and

Read Stata 13 file in R

我只是一个虾纸丫 提交于 2019-12-17 07:27:27
问题 Is there a way to read a Stata version 13 dataset file in R? I have tried to do the following: > library(foreign) > data = read.dta("TEAdataSTATA.dta") However, I got an error: 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,

Read Stata 13 file in R

牧云@^-^@ 提交于 2019-12-17 07:27:03
问题 Is there a way to read a Stata version 13 dataset file in R? I have tried to do the following: > library(foreign) > data = read.dta("TEAdataSTATA.dta") However, I got an error: 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,

How do I create a “macro” for regressors in R?

喜你入骨 提交于 2019-12-17 06:51:52
问题 For long and repeating models I want to create a "macro" (so called in Stata and there accomplished with global var1 var2 ... ) which contains the regressors of the model formula. For example from library(car) lm(income ~ education + prestige, data = Duncan) I want something like: regressors <- c("education", "prestige") lm(income ~ @regressors, data = Duncan) I could find is this approach. But my application on the regressors won't work: reg = lm(income ~ bquote(y ~ .(regressors)), data =

Examples of the perils of globals in R and Stata

北战南征 提交于 2019-12-17 04:20:08
问题 In recent conversations with fellow students, I have been advocating for avoiding globals except to store constants. This is a sort of typical applied statistics-type program where everyone writes their own code and project sizes are on the small side, so it can be hard for people to see the trouble caused by sloppy habits. In talking about avoidance of globals, I'm focusing on the following reasons why globals might cause trouble , but I'd like to have some examples in R and/or Stata to go

Assigning rank to a variable based on 2 other variables in stata

半世苍凉 提交于 2019-12-14 04:22:37
问题 I have a longitudinal data with some variables as: firm id , event date , abnormal return , where event date is acquisition announcement date by each firm and abnormal return is the event-announcement return for each firm over a window of 5 days (-2,+2). Here each sample firm engages in multiple acquisitions over a pre-defined period. For e.g., I have 200 firms, each having multiple abnormal return-observations for the period 1999-2011. Therefore, each firm has at least 2 such observations