stata

Chinese Characters in Stata

↘锁芯ラ 提交于 2019-12-14 03:29:49
问题 I am working on a data set that contains Chinese characters. Stata displays these as gibberish and I need to be able to read these. I could not find a Chinese language pack for Stata. Does something like this exist? I am using Windows 7 Professional and StataSE 13 (64 bit). 回答1: Go to Control Panel->Language->Advanced Settings . Click into Apply language settings to the welcome screen, system accounts, and new user accounts . In Administrative tab, under language for non-Unicode programs ,

Transform string monthly dates in Stata

送分小仙女□ 提交于 2019-12-14 02:36:36
问题 I have a problem in Stata with the format of the dates. I believe it is a very simple question but I can't see how to fix it. I have a csv file (file.csv) that looks like v1 v2 01/01/2000 1.1 01/02/2000 1.2 01/03/2000 1.3 ... 01/12/2000 1.12 01/02/2001 1.1 ... 01/12/2001 1.12 The form of v1 is dd/mm/yyyy. I import the file in Stata using import delimited ...file.csv v1 is a string variable, v2 is a float. I want to transform v1 in a monthly date that Stata can read. My attempts: 1) gen Time =

Drop observations in panel data using Stata

自闭症网瘾萝莉.ら 提交于 2019-12-13 22:30:25
问题 I have longitudinal data on individuals (id) surveyed in two years. Some individuals were not surveyed the second time. I would like to drop all outcomes on individuals surveyed only once so that I am left with a balanced data set. How do I do this in Stata? 回答1: This might do it for you: by id, sort: drop if _N!=2 The by id will execute the command following the colon separately for each value of id , and _N will be the number of observations with that id . 来源: https://stackoverflow.com

Stata: Assign labels to range of variables with a loop

笑着哭i 提交于 2019-12-13 21:03:57
问题 Let's say I have 60 variables, none with similar naming patterns. I want to assign labels to all variables, which I stored locally. So for example local mylabels "dog cat bird" However I am struggling with the exact expression of the loop. Do I have to store my variable range globally and then use a foreach? Or do I use forvalues? Edit: I was referring to variable labels. I managed to create a loop, similar to the method used here http://www.stata.com/support/faqs/programming/looping-over

Loop for changing date format and generating graphs

你说的曾经没有我的故事 提交于 2019-12-13 20:28:54
问题 I would like to loop through a number of csv files in order to change the format of date variables and generate graphs each with a title that is simply the name of the respective file. Here is an example of one of the csv files created using dataex : clear input str32 eventname str10 scrapedate float(average thpercentile v5 v6) "EventName" "2015-12-15" 136.9255 83.2 104.875 148.75 "EventName" "2015-12-16" 130.4555 78.55 99 138.22 "EventName" "2015-12-17" 123.66705 72.7 90.25 131.2 "EventName"

Find last date of year

冷暖自知 提交于 2019-12-13 11:14:32
问题 I have a string variable with years: clear input str4 year "2012" "2013" "2014" "2015" "2016" "2017" "2018" end When I do the following I do not get 31dec201X everywhere: g date = date(year, "Y") + 364 form date %td l +------------------+ | year date | |------------------| 1. | 2012 30dec2012 | 2. | 2013 31dec2013 | 3. | 2014 31dec2014 | 4. | 2015 31dec2015 | 5. | 2016 30dec2016 | |------------------| 6. | 2017 31dec2017 | 7. | 2018 31dec2018 | +------------------+ How can I get the last date

Develop a program in Stata to handle multiple files in work folder just like SAS using tempfile

淺唱寂寞╮ 提交于 2019-12-13 09:58:17
问题 I am developing this wrapper around tempfile in Stata to handle multiple datasets at the same time without having to save them in current directory. So in essence I want Stata to mimic SAS, and that is the reason the program name is work; the initial code is without any options and minimal functionality. I have adhere to your advice not to tokenize and program works; however the issue is once I recall the tempfile in further program, this program (work) do not pass the handle to the next to

Stata local based on other local

北城余情 提交于 2019-12-13 09:17:46
问题 I am trying to use local with the value of an earlier use of local. An example: I want to define "final" and I want it to contain "var1 var2". However, I want to define "temp" first, and reuse its contents in the definition of final. Here is what I tried: local temp "var2" local final "var1 " `temp' Can anyone tell me what I am doing wrong? 回答1: An example that works: // example data sysuse auto, clear // what you want local first weight local second `first' mpg // example use of local second

In Stata, how can I change the format of a date from “2010-01-11 00:00:00” to “1/11/2010”?

余生颓废 提交于 2019-12-13 08:59:29
问题 I am currently trying to change the format of a date from "2010-01-11 00:00:00" to "01-11-2010" or "1/11/2010". Currently "2010-01-11 00:00:00" is in a string format. I have tried to coerce using the date() function but it never returns to the point where Stata can recognize and sort. Would anyone have any idea how to do this? 回答1: It's best if for future questions you post attempted code and why it's not working for you. Maybe this works in your case: clear all set more off *----- example

How to get observations as a list in Stata?

旧时模样 提交于 2019-12-13 08:35:19
问题 Stata has r() macro for values that some commands return ( return list after the command). I need similar access to x after list x if y == 1 , but list returns only r(N) , not values themselves. Is it possible to get the observations as a local or global macro to refer to it in the code? 回答1: Try levelsof command to get distinct values. It's the cat's pajamas. 回答2: One way to save values of all observations (i.e. including repeated) is with a loop: clear set more off *----- exmple data -----