stata

Getting SciPy quantiles to match Stata xtile function

流过昼夜 提交于 2019-12-08 03:24:13
问题 I've inherited some old Stata code (Stata11) that uses the xtile function to categorize observations in a vector by their quantiles (in this case, just the standard 5 quintiles, 20%, 40%, 60%, 80%, 100%). I'm trying to replicate a piece of the code in Python and I am using the SciPy.stats.mstats function mquantiles() for the computation. As near as I can tell from Stata documentation and searching online, the Stata xtile method tries to invert the empirical CDF of the data, and uses the equal

foreach loop running but not giving results

送分小仙女□ 提交于 2019-12-07 19:32:33
I am having trouble running a foreach loop. The loop runs without error but gives no output. Can someone tell me what they think might be going on? Many thanks in advance! Here is the code: cd "O:\RESEARCH\ikhilko\Subway Big Data project" local datafiles : dir . files "*.txt" foreach file in `datafiles' { insheet using `file', clear insheet using `file', drop v9-v43 save date1, replace } UPDATE: Interestingly, the code runs when I just type it into the command line, rather than doing it from the .do file, any idea what might be going on there? It is important to note that local macros are

Stata's xtlogit (fe, re) equivalent in R?

假如想象 提交于 2019-12-07 19:05:06
问题 Stata allows for fixed effects and random effects specification of the logistic regression through the xtlogit fe and xtlogit re commands accordingly. I was wondering what are the equivalent commands for these specifications in R. The only similar specification I am aware of is the mixed effects logistic regression mymixedlogit <- glmer(y ~ x1 + x2 + x3 + (1 | x4), data = d, family = binomial) but I am not sure whether this maps to any of the aforementioned commands. 回答1: The glmer command is

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

限于喜欢 提交于 2019-12-06 13:53:35
问题 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

In Stata, how do I add variable labels from a separate csv file?

荒凉一梦 提交于 2019-12-06 11:19:19
I have a set of csv files that are very simple to load into Stata using the -insheet- command. But they have very uninformative variable names. For each of these files, I also have a file of metadata consisting of two columns: the original (uninformative) variable names, and a description of what the variables actually mean. I'd like to use these metadata files to create variable labels, preferably without going through and typing up all the separate label commands or turning the metadata file into a dictionary for each file. It seems like there must be a quick way of loading the metadata file

how to make tables out for Spearman correlation table? [duplicate]

风格不统一 提交于 2019-12-06 11:12:40
This question already has an answer here : How to export Spearman correlations (1 answer) Closed 3 months ago . I need to get a Spearman and Pearson correlation table using Stata. Here is what I did to get the results in a table format. estpost correlate sp_rating srating mrating split split_neg split_ord split_neg_ord tier1_risk tier1_leverage st1 sl mt1 ml adt1 adl dt1 dl offering_amt maturity2 security enhance timeliness validity disc loan_at cash_dep trading_at real_est intangible other_at sec_sum assets_sold all_residual secinc_ta, matrix quietly esttab . using "root4.rtf", replace notype

How to reshape long to wide data in Stata?

让人想犯罪 __ 提交于 2019-12-06 10:09:54
I have the following data: id tests testvalue 1 A 4 1 B 5 1 C 3 1 D 3 2 A 3 2 B 3 3 C 3 3 D 4 4 A 3 4 B 5 4 A 1 4 B 3 I would like to change the above long data format into following wide data. id testA testB testC testD index 1 4 5 3 3 1 2 3 3 . . 2 3 . . 3 4 3 4 3 5 . . 4 4 1 3 . . 5 I am trying reshape wide testvalue, i(id) j(tests) It gives error because there are no unique values within tests . What would be the solution to this problem? You need to create an extra identifier to make replicates distinguishable. clear input id str1 tests testvalue 1 A 4 1 B 5 1 C 3 1 D 3 2 A 3 2 B 3 3 C 3

Stata's xtlogit (fe, re) equivalent in R?

我们两清 提交于 2019-12-06 09:08:18
Stata allows for fixed effects and random effects specification of the logistic regression through the xtlogit fe and xtlogit re commands accordingly. I was wondering what are the equivalent commands for these specifications in R. The only similar specification I am aware of is the mixed effects logistic regression mymixedlogit <- glmer(y ~ x1 + x2 + x3 + (1 | x4), data = d, family = binomial) but I am not sure whether this maps to any of the aforementioned commands. The glmer command is used to quickly fit logistic regression models with varying intercepts and varying slopes (or, equivalently

How to get Stata to report zeroes in tabulate

巧了我就是萌 提交于 2019-12-06 04:11:35
I'm trying to use the tabulate command in Stata to create a time series of frequencies. The problem arises when I try to combine the output of tabulate after running through each date. tabulate will not include 0 as an entry when no observation exists for a value of the variable in question. For instance, if I wanted to count the 10, 11 and 12 year olds in a class over a three-year period Stata might output (8) if only one of the groups were represented and thus we don't know which group the 8 students belonged to: it could be (0,8,0) or (0,0,8). This is not a problem if the time series is

Importing foreign languages from csv file to Stata

浪子不回头ぞ 提交于 2019-12-05 22:04:08
I am using Stata 12. I have encountered the following problems. I am importing a bunch of .csv files to Stata using the insheet command. The datasets may conclude Russian, Croatian, Turkish, etc. I think they are encoded in "UTF-8". In .csv files, they are correct. After I imported them into Stata, the original strings are incorrect and become the strange characters. Would you please help me with that? Does Stat-Transfer can solve the problems? Does it support .csv format? For example, the original file is like: My code is like: insheet using name.csv, c n save name.dta,replace The result is