Hello Statalist,
I am trying to generate a new variable based on an existing variable. The existing variable (for economic sectors) has 1,300 individual observations, and consists of a number from 01 to 99000. To make sectors more manageable I want to create a new variable which uses only the first two numbers of the sector. So if the old variable is 01 or 011 or 01110 or 011120 or 0113 or 01113, the new one should be "01". The same for all values in my old variable starting with "02" etc.
What I would need is a sort of wildcard, to do for instance:
gen sector_new = 1 if sector_old == 01*
replace sector_new = 2 if sector_old == 02*
etc
However as I understand it wildcards can only be used for variables and not for singular values, so the above command does not work and I am looking for a way to implement this.
The problem why I can't use the inrange command or inlist command (or simply tell state to gen a new var b if a (my old var) is between 0 and for instance 01900) is that the value of my old variable can be 2,3,4 or 5 digits. So if I would say "generate new variable if the value is between 0 and 01900", it would also include for instance 02, 021, 022 etc, which I do not want as these need to go in a separate category.
I hope the explanation is understandable, and would very much appreciate your help.
Kind regards
Elisabeth
Related Posts with Generating New Variable with several values of one existing variable using "Wildcards"
Forval simulation, 100 timesDear Stalist, I want to run and repeat this command line 100 times and then after the repetition, ta…
Tabplot: how to change the position of the showval for a particular barHi List, I used tabplot to draw nine subplots. My codes are as below: Code: tabplot Wp [iw=iimpa…
Correcting standard errors for a fixed effects Poisson modelHi all, I'm looking at the effect of fire occurrence on the number of visits to National Forests an…
Problem with two step difference/system GMM estimator using "xtabond2"Dear all, It is my first post on Statalist, I hope I am doing everything fine, I read all the FAQs …
marginal effects after STINTREGHi, I am using STINTREG to analyze interval data and as expected, the output is hazard ratios. I wa…
Subscribe to:
Post Comments (Atom)
0 Response to Generating New Variable with several values of one existing variable using "Wildcards"
Post a Comment