Dear Statalist,
I hope this finds you well - my first post so please be gentle.
I regularly use data-sets which contain a very methodical naming convention and I'm trying to write some script to combine them.
The naming convention is variable_e1_c1 (incomplete observations 1-10), variable_e1_c2 (incomplete observations 11-20), variable_e1_c3 (incomplete observations 21-30), variable_e1_c4 (incomplete observations 31-40) where the variables in the data set I want to combine will all contain the same variable-name_e-number. I've started with a few approaches, however, I don't know how to pass the variable name into logical test after running say:
- ds, has(varl *_e1*).
If varname == "*_c*" {then do}.
I've also tried the approach with:
- foreach x of varlist *_e2_* {
but again I'm lost as to how to apply logic gates to the value of `x' as it takes the value of the first observation where .
Ultimately I'm keen on generating a new variable where all the observations take a similar convention and I currently use the tedious approach of copy and paste a few lines of code as such:
gen Bar=.
replace Bar= real(biadlyn_e1_c1) if biadlyn_e1_c2==.
replace Bar= biadlyn_e1_c2 if real(biadlyn_e1_c1)==.
I apologies is this thread has been covered and would appreciate a link and also do note although I'm not new to programming I am new to STATA and it's handling power so any advice would be most welcome.
Kind regards
Related Posts with Generating new variables based on a variable naming convention
Pooled OLS, fixed & random effects: Panel DataHey everyone, (Data description is posted in the buttom) I'm currently writing by bachelor at Copenh…
Demeaning and standardizing variables in panel regressionHello everyone, I am analyzing a panel data set with 55 countries. My dependent variable is firm eq…
Topic impact access to microfinancial institution for ensuring consumption because of health shock : omitted because of collinearityIam currently writing for my undergraduated thesis. I have large panel data in year 2007 and 2014. m…
No constant in fixed-effect regressionDear all: Hope you are doing well and healthy. I am writing to ask a quick question about the fixed…
Looping regression to determine one set of control variables that make models significantHi everyone, I have one dependent variable Y, four independent variables X1 X2 X3 X4, 12 control va…
Subscribe to:
Post Comments (Atom)
0 Response to Generating new variables based on a variable naming convention
Post a Comment