Dear,
I want to collapse the years into periods of, say, two years each. For example, if I have a panel from 1990 to 1995, I want period I = 1990-1991, period II = 1992-1993, and period III = 1993 & 1994. Within each period, I will then calculate the average (mean) or identify the mode for each variable.
How can I do that in Stata?
Let me give an example with the following made-up dataset:
input str10 country year x y
"Indonesia" 1990 24 36
"Indonesia" 1991 28 22
"Korea" 1990 38 27
"Korea" 1991 42 73
"China" 1990 124 458
"China" 1991 12 24
end
I want to collapse 1990 and 1991 into just one period, so the x-value for Indonesia would be (24 + 28)/2 and the corresponding y-value (36 + 22)/2.
Now, imagine I also have the row for years 1992-2021. That means I can't just do "collapse varlist, by (country)". I will first need to create a variable called "period" that takes the value = 1 for 1990 & 1991, = 2 for 1992 & 1993, and so on.
I could do that manually one by one, but there must be a smart way to do this in Stata.
Is it possible to get help?
Best,
Related Posts with Collapse and generate average values
How to deal with I(1) and I(0) variables in econometric analysisDear Users, I am working on a balanced panel with 50 countries observed over 19 years. My main depe…
Difference between areg and xtset for firmxyear fixed effectDear all, I would like to find the effect of bank liquidity risk (my independent variable) on loan…
How to tell Stata not to ignore missing values in bysort: egen mean commandDear Stata-Listers, I am posting a question for the first time, so I hope I'm doing it correctly. …
I'm converting a date but the new date variable is all missing valuesI'm using Stata 14.2. i have a dataset with dates in a string variable e.g. 01-Apr-2018. I have used…
Estimating Modified Jones Model ,No final values generated for Jones modelHi, I am trying to estimate the discretionary accruals through the modified Jones model in Stata. T…
Subscribe to:
Post Comments (Atom)
0 Response to Collapse and generate average values
Post a Comment