Hi all,
I have created a categorical variable (values 1 through 5) in excel based on certain characteristics of US states in a 20 year time period.
I have a large data set with over 2 million rows and I am trying to assign the value of the categorical variable to each row in my data set based on the state and the year.
What I have tried so far is:
gen state_year = 1
replace state_year = 5 if (year==1962 & state==1)
And so on etc.
However, since there are a 1000 combinations of states and years (50*20), this is going to take a very long time to code in a do-file.
Is there a way to import my excel file so that it creates a variable and assigns the value of that variable depending on what is in the excel?
I have attached a screenshot of the first few rows of my excel document.
Array
Any help would be much appreciated. Thanks in advance!
Harry
Related Posts with Creating a new variable based on the value of other variables
Stata Journal Editors' Prize 2020: Congratulations to Daniel Klein!The Editors of the Stata Journal (H. Joseph Newton and myself) are delighted to announce the award o…
Help creating a graph, and add confidence intervals to another graphHi, Question 1: I have a dataset with patent count, a dummy to check wheter a firm engages in a M&a…
Error "Option not allowed" when creating coefHey guys, my goal is to regress the natural logarithm of total industry sales and an index variable…
how to code the following on statai have a group of friends around 50 .. and all make a choice of colour pink 10 , red 6 , black 10 , …
Can factor variables and factorial interactions be used in "parmby"? If not, what is the alternative?Dear all, I wish to make a dataset of estimates - the treatment coefficient by year and its 95% con…
Subscribe to:
Post Comments (Atom)
0 Response to Creating a new variable based on the value of other variables
Post a Comment