stata

Stata error: not found in list of covariates

五迷三道 提交于 2019-12-12 05:00:09
问题 I want to plot an interaction effect among two variables. margins SentiSat_Rounded#PriceReduction I get the following error: 'SentiSat_Rounded' not found in list of covariates r(322); The variables are present in the dataset. Also if the variable is not present in the dataset it throws a different error, like variable X not found Can you please suggest what is meant by not present in list of covariates? To find covariates I came across this code: program covars, rclass version 8 capture local

How to Import Data in .bson File

試著忘記壹切 提交于 2019-12-12 04:59:50
问题 I would like to import the data found here: https://thecodebarbarian.wordpress.com/2014/02/14/crunching-30-years-of-nba-data-with-mongodb-aggregation/ (you can download the data towards the bottom in the Conclusion section). The data comes in two files. First, a file called games.metadata.json . The complete contents is here: { "indexes" : [ { "v" : 1, "key" : { "_id" : 1 }, "ns" : "nba.games", "name" : "_id_" } ] } And the other file is called games.bson . A sample of this file is: @_idRÚüë

Reshaping panel data

泪湿孤枕 提交于 2019-12-12 04:56:09
问题 I need to reshape my data for panel data analysis. I searched the internet and only found out how to get the desired results by using Stata; however I am supposed to use R and Excel. My initial and final data(the desired result) looks very similar to the given in the first page of this example of reshaping data with Stata. http://spot.colorado.edu/~moonhawk/technical/C1912567120/E220703361/Media/reshape.pdf Is it attainable with R or just Excel? I tried using melt function from reshape2

Why is x-axis in graph always alphabetical? How can I order x-axis according to my data?

送分小仙女□ 提交于 2019-12-12 04:48:37
问题 I have a list of countries, gdp, and 2 variables for employment cntry gdppc ie_dummy fe_dummy Data is initially ordered alphabetically according to cntry, so i first gsort -gdppc Sort it by descending GDP, highest to lowest. Now when I generate my graph graph bar ie_dummy fe_dummy, over(cntry) stack The x-axis which country is still alphabetically ordered, not reflecting the order of the data. Any ideas? 回答1: Wherever this idea originates (MS Excel, maybe), the lesson here is that you don't

Management of spell data: months spent in given state in the past 24 months

非 Y 不嫁゛ 提交于 2019-12-12 04:45:00
问题 I am working with a spell dataset that has the following form: clear all input persid start end t_start t_end spell_type year spell_number event 1 8 9 44 45 1 1999 1 0 1 12 12 60 60 1 2000 1 0 1 1 1 61 61 1 2001 1 0 1 7 11 67 71 1 2001 2 0 1 1 4 85 88 2 2003 1 0 1 5 7 89 91 1 2003 2 1 1 8 11 92 95 2 2003 3 0 1 1 1 97 97 2 2004 1 0 1 1 3 121 123 1 2006 1 1 1 4 5 124 125 2 2006 2 0 1 6 9 126 129 1 2006 3 1 1 10 11 130 131 2 2006 4 0 1 12 12 132 132 1 2006 5 1 1 1 12 157 168 1 2009 1 0 1 1 12

How to get the difference of two variables, when there are missing values?

こ雲淡風輕ζ 提交于 2019-12-12 03:49:47
问题 I have two variables A & B , and I want to get A - B for a new variable called C . For that I used generate C = A - B . But it gives some missing values in C , when either A or B contains missing values. For example, if A is 5000 while B is missing, it gives missing for C , even though I want C as 5000. So I want to consider those missing values as zeros & get the answer. How can I do it in Stata? 回答1: gen C = cond(missing(A, B), min(A, B), A - B) which is short-hand for gen C = A - B replace

creating variables using loop or apply in r

旧时模样 提交于 2019-12-12 03:33:04
问题 I'm trying to create a series of variables in R based on an ifelse function: comp1990<-ifelse(year_begin<1990 & year_end>1990,1,0) comp1991<-ifelse(year_begin<1991 & year_end>1991,1,0) comp1992<-ifelse(year_begin<1992 & year_end>1992,1,0) I'm doing this for years 1970-2007. Right now, I just have a line for every single year. In stata, I could do this in the following way: forvalues n=1970(1)2007 { gen comp\`n'== (year_begin<\`n' & year_end>\`n') } Is there a similarly straightforward way to

Looking up data within a file versus merging

被刻印的时光 ゝ 提交于 2019-12-12 03:25:55
问题 I have a file that look at ratings that teacher X gives to teacher Y and the date it occurs clear rating_id RatingTeacher RatedTeacher Rating Date 1 15 12 1 "1/1/2010" 2 12 11 2 "1/2/2010" 3 14 11 3 "1/2/2010" 4 14 13 2 "1/5/2010" 5 19 11 4 "1/6/2010" 5 11 13 1 "1/7/2010" end I want to look in the history to see how many times the RatingTeacher had been rated at the time they make the rating and the cumulative score. The result would look like this. rating_id RatingTeacher RatedTeacher Rating

Can't eliminate rows with na. Stata says ambiguous abbreviation

半世苍凉 提交于 2019-12-12 03:06:49
问题 In the dta file, there is this column ColumnA 1 2 1 na . . so I want to eliminate na and . But when I do drop if ColumnA==na then Stata says (in red) na ambiguous abbreviation What is this? How can I successfully eliminate rows with "na" ? 回答1: This means that you have two (or more) variables that begin with the stub na . Stata interprets what you typed as drop the observation if the value of ColumnA is equal to value of variable na . Since Stata does not know which na variable you mean, it

Outsheet to create a comma separated .txt

删除回忆录丶 提交于 2019-12-12 02:07:01
问题 My variables in Stata are of the form: First Name: Allen Last Name: Von Schmidt Birth Year: 1965 County: Cape May State: New Jersey First Name: Lee Roy Last Name: McBride Birth Year: 1967 County: Cook State: Illinois I would like to outsheet them to create comma separated rows in a .txt as: Allen,Von Schmidt,1965,Cape May, New Jersey Lee Roy,McBride,1967,Cook, Illinois How can I use outsheet (or another command) to do this? Do I need to make the numerics into strings first? Do I need to add a