Hello,
Can you please help me with the following issue: I want to compute returns (ret_eom) based on two conditions, i.e. for each monthly observation (mo_dates) in my sample and for each decile based on the credit rating (decile_cr_monthly).
I computed the returns using the following command:
bysort mo_dates decile_cr_monthly : egen ptf_ret_crat=mean(ret_eom)
Naturally, the variable generated ptf_ret_crat has the same number of observations as the original sample (containing many duplicates).
Is there a way to generate a new variable satisfying these conditions and having only the unique observations?
I was able to identify the number of unique observations using the following code:
by ptf_ret_crat, sort: gen nvals = _n == 1
replace nvals = sum(nvals)
replace nvals = nvals[_N]
So for example, if I have 12 months and 10 deciles, the new variable should have 120 observations (which is also what nvals retrieves).
Is there a way to store a new variable containing only these unique observations, while sorting them based on the date and rating?
Thank you for your help!
Related Posts with Store a new variable with unique observations and missing otherwise
Trimming percentiles within each age categoryHello stata-users, I have come across code for trimming data globally but not what I am specifically…
A question on insheetjson - Keep getting "Invalid column name/selector" error message when using -insheetjson-I am trying to get some data from the API of American Community Survey by using insheetjson. But whe…
How to tag the most recent fiscal year end value based on the calandar time?Dear Stata experts, I would like to find the most recent fiscal-year-end investment based on the ca…
How to deal with non-linear relationships in linear modelsDear all, I estimated a linear regression model on multiply imputed data. I regress income on a ran…
marginal effects after bayesian mlogitDear all, I'm running a bayesian mlogit model using the "bayes:" prefix and I'm trying to compute ma…
Subscribe to:
Post Comments (Atom)
0 Response to Store a new variable with unique observations and missing otherwise
Post a Comment