stata

Bring value labels to variable labels when reshaping wide

点点圈 提交于 2020-01-05 05:47:11
问题 In Stata, I would like to be able to bring value labels up into variable labels when reshaping wide. My raw data looks like this: patient hosp_id hosp_name charges Andrew 1 Springfield General $10 Barry 1 Springfield General $20 Crista 2 Lincoln Medical Center $10 Doris 2 Lincoln Medical Center $15 Ellen 1 Springfield General $15 Faye 3 Memorial Hospital $35 I then label the values of hosp_id and reshape wide . label define hosp_names 1 "Springfield General" 2 "Lincoln Medical Center" 3

Save .dta files with long strings in R

老子叫甜甜 提交于 2020-01-05 04:35:15
问题 I have to save an R-dataset in Stata's .dta format. The dataset contains, among other data, a single column containing long strings (column 3). test data: r_data <- data.frame( ae= 1, be= 2, ce= "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet"

Running a Perl script within a Stata .do file

半腔热情 提交于 2020-01-05 00:44:50
问题 Is it possible to execute a Perl script within a Stata .do file? I have a Stata .do file in which I make some manipulations to the data set and arrange it in a certain way. Then I have a Perl script in which I take one of the variables at this point, apply a Perl package to it, and make a transformation to one of the variables. In particular, I use Perl's NYSIIS function, resulting in a very short script. After this output is provided in Perl, I'd like to continue with some additional work in

Create composite variable of products

让人想犯罪 __ 提交于 2020-01-04 09:14:07
问题 I have data on discounted products for each year: * Example generated by -dataex-. To install: ssc install dataex clear input float(code year) strL product 15328 2007 "Coca-Cola" 15328 2007 "Coca-Cola Diet" 15328 2008 "Pepsi" 15328 2010 "Pepsi Diet" 15328 2010 "Dr Pepper" 15328 2011 "7 Up" 15328 2012 "Aquafina" 15328 2012 "Fanta" 15328 2013 "Amp Energy" 15328 2013 "Manhattan Special" 15328 2013 "Jolt Cola" 15328 2013 "Mountain Dew" 15328 2014 "Cocofina" 15328 2014 "Highland Spring" 15328 2015

Get the date from each sentence in a variable

落花浮王杯 提交于 2020-01-04 05:48:48
问题 I have the following text: This sentence contains a certain date which is 06-08-2003. On this date, 29-12-1945 my grandmother was born. 12-04-1997 was an important year for celebrations. I would like to get the date in a variable but the substr() function does not seem to work? 回答1: You do not show us your code so we cannot tell you what is wrong with substr() . That said, the substr() function works as intended if you know the position of the desired item in a string . In this case, the

How to see if all values within group are unique/identify those that aren't

痞子三分冷 提交于 2020-01-03 02:57:15
问题 Say that I have data like this: group value 1 fox 1 fox 1 fox 2 dog 2 cat 3 frog 3 frog 4 dog 4 dog I want to be able to tell if all values of value are the same within group . Another way to see this is if I could create a new variable that contains all unique values of value within group like the following: group value all_values 1 fox fox 1 fox fox 1 fox fox 2 dog dog cat 2 cat dog cat 3 frog frog 3 frog frog 4 dog dog 4 dog dog As we see, all groups except group 2 have only one distinct

How to reshape long to wide data in Stata?

空扰寡人 提交于 2020-01-02 08:59:05
问题 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? 回答1: You need to create an extra identifier to

Alternative IDE for Stata

隐身守侯 提交于 2019-12-31 15:51:05
问题 I am used to R-studio for R, which has some features such as guessing what function you are trying to type, by pressing TAB . However, I can't find any integrated development environments (IDE) for Stata. Is there one? 回答1: There is no full-blown IDE for Stata. The question comes up pretty often at Stata User Group meetings, and StataCorp developers always say that they work in text editors. See http://fmwww.bc.edu/repec/bocode/t/textEditors.html -- there's plentiful customization for syntax

Alternative IDE for Stata

淺唱寂寞╮ 提交于 2019-12-31 15:50:36
问题 I am used to R-studio for R, which has some features such as guessing what function you are trying to type, by pressing TAB . However, I can't find any integrated development environments (IDE) for Stata. Is there one? 回答1: There is no full-blown IDE for Stata. The question comes up pretty often at Stata User Group meetings, and StataCorp developers always say that they work in text editors. See http://fmwww.bc.edu/repec/bocode/t/textEditors.html -- there's plentiful customization for syntax

Alternative IDE for Stata

痞子三分冷 提交于 2019-12-31 15:50:19
问题 I am used to R-studio for R, which has some features such as guessing what function you are trying to type, by pressing TAB . However, I can't find any integrated development environments (IDE) for Stata. Is there one? 回答1: There is no full-blown IDE for Stata. The question comes up pretty often at Stata User Group meetings, and StataCorp developers always say that they work in text editors. See http://fmwww.bc.edu/repec/bocode/t/textEditors.html -- there's plentiful customization for syntax