This is also my first post and I basically am looking for an easier way to code labels.

So I have a data base that has the same information for different animals.

So our list of animals is: cow, bulls, chickens, buffalos, and sheep.

We have information about each animal: number of (animal) farmer own, number of (animal) bought, number of (animal) sold, and number of (animal) died.

The variables are coded the following way :

First by type of information so for example, number of (animal) owned is coded as q1, bought is q2, etc.

Each animal is coded as a1 (cows), a2 (bulls) etc.

So our variable list is q1_a1; q1_a2;….. q2;_a1 etc.

Where q1_a1 is number of cows a farmer owns, q1_a2 number of bulls a farmer owns, q2_a1 number of cow that were bought. I have a problem with the labeling:

I am now labeling each of them and I am doing the following:

label variable q1_a1 “Q1.A1 Number of cows owned by Farmer”

label variable q1_a2 “Q1.A2 Number of bulls owned by Farmer”

label variable q1_a2 “Q1.A2 Number of bulls owned by Farmer”

Code:

forvalues x=1 (1) 5 { label variable q1_a`x' "Q1.A `x' Number of (animals) owned" }

Is there a way to do this through a loop?

I hope this is clear!!

Thank you so much!

]]>

I am working with panel data for EU28 NUTS2 regions, calculating the capital and knowledge stock according to perpetual inventory method.

Unfortunately there are recurrent missing data, that I am correctly taking into account when using the solution I propose. In particular, the last code doesn't work, but I'll put all the process to arrive to that, just in case you have a quicker way to do so.

Code:

clear input str5 tl2 int year float(capital_stock_ gr_gfcf_07_00_) long FCFormation " AT33" 1990 . . . " AT33" 1991 . . . " AT33" 1992 . . . " AT33" 1993 . . . " AT33" 1994 . . . " AT33" 1995 . . . " AT33" 1996 . . . " AT33" 1997 . . . " AT33" 1998 . . . " AT33" 1999 . . . " AT33" 2000 47952.36 .03020859 5045 " AT33" 2001 . . 4941 " AT33" 2002 . . 5000 " AT33" 2003 . . 5336 " AT33" 2004 . . 4970 " AT33" 2005 . . 5724 " AT33" 2006 . . 5893 " AT33" 2007 . . 6233 " AT33" 2008 . . 6454 " AT33" 2009 . . 5965 " AT33" 2010 . . 6027 " AT33" 2011 . . 6702 " AT33" 2012 . . 6871 " AT33" 2013 . . 7095 " AT33" 2014 . . 7268 " AT33" 2015 . . 7727 " AT33" 2016 . . . " AT33" 2017 . . . " BE1" 1990 . . . " BE1" 1991 . . . " BE1" 1992 . . . " BE1" 1993 . . . " BE1" 1994 . . . " BE1" 1995 . . . " BE1" 1996 . . . " BE1" 1997 . . . " BE1" 1998 . . . " BE1" 1999 . . . " BE1" 2000 . .08150125 . " BE1" 2001 . . . " BE1" 2002 . . . " BE1" 2003 . . 8492 " BE1" 2004 . . 10014 " BE1" 2005 . . 10534 " BE1" 2006 . . 11321 " BE1" 2007 . . 11765 " BE1" 2008 . . 12163 " BE1" 2009 . . 11434 " BE1" 2010 . . 11115 " BE1" 2011 . . 11388 " BE1" 2012 . . 11460 " BE1" 2013 . . 11938 " BE1" 2014 . . 12594 " BE1" 2015 . . 13475 " BE1" 2016 . . . " BE1" 2017 . . . end

Code:

bysort tl2_n (year): replace gr_gfcf_07_00_ = gr_gfcf_07_00_[_n-1] if missing(capital_stock[_n-1]) & year>=2001 & year<=2007 forvalues i=1(1)299 { forvalues j=2001(1)2007 { quietly replace capital_stock_ = (FCFormation/(gr_gfcf_07_00_ +0.075)) /// if year==`j' & tl2_count==`i' } }

Code:

clear input str5 tl2 int year float(capital_stock_ gr_gfcf_07_00_) long FCFormation " AT33" 1990 . . . " AT33" 1991 . . . " AT33" 1992 . . . " AT33" 1993 . . . " AT33" 1994 . . . " AT33" 1995 . . . " AT33" 1996 . . . " AT33" 1997 . . . " AT33" 1998 . . . " AT33" 1999 . . . " AT33" 2000 47952.36 .03020859 5045 " AT33" 2001 . . 4941 " AT33" 2002 . . 5000 " AT33" 2003 . . 5336 " AT33" 2004 . . 4970 " AT33" 2005 . . 5724 " AT33" 2006 . . 5893 " AT33" 2007 . . 6233 " AT33" 2008 . . 6454 " AT33" 2009 . . 5965 " AT33" 2010 . . 6027 " AT33" 2011 . . 6702 " AT33" 2012 . . 6871 " AT33" 2013 . . 7095 " AT33" 2014 . . 7268 " AT33" 2015 . . 7727 " AT33" 2016 . . . " AT33" 2017 . . . " BE1" 1990 . . . " BE1" 1991 . . . " BE1" 1992 . . . " BE1" 1993 . . . " BE1" 1994 . . . " BE1" 1995 . . . " BE1" 1996 . . . " BE1" 1997 . . . " BE1" 1998 . . . " BE1" 1999 . . . " BE1" 2000 . .08150125 . " BE1" 2001 . .08150125 . " BE1" 2002 . .08150125 . " BE1" 2003 54261.55 .08150125 8492 " BE1" 2004 63986.71 .08150125 10014 " BE1" 2005 67309.37 .08150125 10534 " BE1" 2006 72338.086 .08150125 11321 " BE1" 2007 75175.12 .08150125 11765 " BE1" 2008 . . 12163 " BE1" 2009 . . 11434 " BE1" 2010 . . 11115 " BE1" 2011 . . 11388 " BE1" 2012 . . 11460 " BE1" 2013 . . 11938 " BE1" 2014 . . 12594 " BE1" 2015 . . 13475 " BE1" 2016 . . . " BE1" 2017 . . .

Code:

forvalues i =1(1)299 { forvalues j=2001(1)2017 { if capital_stock_[_n-1]!=. /// quietly replace capital_stock_=((capital_stock_)*(.925)+(FCFormation)) /// if year==`j' & tl2_count==`i' } }

]]>

Code:

qui drop if (idcase == `c') & (seqnum > `ControlsPerCase')

Code:

qui drop if (idcase == `c') & (seqnum > `ControlsPerCase')

Code:

qui drop if (idcase == `c') & (seqnum > `ControlsPerCase')

Editing now.

Copied from the first block above in the posted version and pasted here without changing while editing.

Code:

qui drop if (idcase == `c') & (seqnum > `ControlsPerCase')

No luck reproducing problem.]]>

I am a student and new to Stata. For a university course I have to model a GARCH model from time series data (euro-dollar exchange rate by the ECB).

I am not allowed to use the built-in modeling procedure but should do the procedure on my own step-by-step.

1. I load the data.

tsset newdate

2. I generate the first difference of the exchange rate.

gen Dvalue = value - L.value

3. I estimate the mean equation as an AR(1) process.

reg Dvalue L.Dvalue

4. I predict the residuals and square them.

predict Dresid, resid

gen Dresid_sq = Dresid^2

5. Now I run a regression of the squared residuals on its lag as a first step to get to the GARCH model.

reg Dresid_sq L.Dresid_sq

6. From this I want to compute the conditional variance of the time series

gen hsq = _b[_cons] + _b[L1.Dresid_sq]*L.Dresid_sq

7. Now, I want to estimate the GARCH(1,1) model.

reg hsq L.hsq L.Dresid_sq

Unfortunately, I get only coefficients no standard errors or p-values.

Would it be an option to do step 7 as a Maximum Likelihood Estimation? How would this be done?

Any help is appreciated. Thanks.

]]>

I wrote the following which simply returns the error "invalid syntax".

The code works when I run with the lab val but without the lab def, suggesting a problem with the label define portion.

Advice please!

local varname "esttype_br_rural esttype_br_total esttype_br_urban [..rest of varnames.]"

local a=wordcount("`varname'")

forval i=1/`a'{

local name=word("`varname'", `i')

lab val `varname' `varname'_lab

lab def `varname'_lab ///

1 "Annual estimate" ///

3 "Three year moving average" ///

5 "Five year estimate" ///

10 "Ten year census"

}]]>