Hi Stata members,
I am currently stuck with the following question. I am practising in Stata how to write a code featuring loops, where I generate a variable which is a multiplication of two variables. To explain this better, this is how my data looks like: I have variables depicting country, year, and the production and unit price of 4 products: car,red bike, bus, black helicopter. It is a simple dataset I made myself with random values, but it is enough for what I would like to do, namely the following: I would like use loops to estimate revenue of each product, where revenue=unit price * production. So I would have then revenue variables for these 4 products. My dataset looks as follows:
I have consulted Stata literature on this, but I could not find a code where I could achieve the desired result. Might anyone have an idea how I could do this?
Best,
Ryan
I am currently stuck with the following question. I am practising in Stata how to write a code featuring loops, where I generate a variable which is a multiplication of two variables. To explain this better, this is how my data looks like: I have variables depicting country, year, and the production and unit price of 4 products: car,red bike, bus, black helicopter. It is a simple dataset I made myself with random values, but it is enough for what I would like to do, namely the following: I would like use loops to estimate revenue of each product, where revenue=unit price * production. So I would have then revenue variables for these 4 products. My dataset looks as follows:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str3 countrycode int year float(production_car unit_price_car production_red_bike unit_price_red_bike production_bus unit_price_bus_ production_black_helicopter unit_price_black_helicopter) "ABW" 1970 1000 10 500 2 40 20 20 30 "ABW" 1971 1000 10 500 2 40 20 20 30 "ABW" 1972 1000 10 500 2 40 20 20 30 "ABW" 1973 1000 10 500 2 40 20 20 30 "ABW" 1974 1000 10 500 2 40 20 20 30 "ABW" 1975 1000 10 500 2 40 20 20 30 "ABW" 1976 1000 10 500 2 40 20 20 30 "ABW" 1977 1000 10 500 2 40 20 20 30 "ABW" 1978 1000 10 500 2 40 20 20 30 "ABW" 1979 1000 10 500 2 40 20 20 30 "ABW" 1980 1000 10 500 2 40 20 20 30 "ABW" 1981 1000 10 500 2 40 20 20 30 "ABW" 1982 1000 10 500 2 40 20 20 30 "ABW" 1983 1000 10 500 2 40 20 20 30 "ABW" 1984 1000 10 500 2 40 20 20 30 "ABW" 1985 1000 10 500 2 40 20 20 30 "ABW" 1986 1000 10 500 2 40 20 20 30 "ABW" 1987 1000 10 500 2 40 20 20 30 "ABW" 1988 1000 10 500 2 40 20 20 30 "ABW" 1989 1000 10 500 2 40 20 20 30 "ABW" 1990 1000 10 500 2 40 20 20 30 "ABW" 1991 1000 10 500 2 40 20 20 30 "ABW" 1992 1000 10 500 2 40 20 20 30 "ABW" 1993 1000 10 500 2 40 20 20 30 "ABW" 1994 1000 10 500 2 40 20 20 30 "ABW" 1995 1000 10 500 2 40 20 20 30 "ABW" 1996 1000 10 500 2 40 20 20 30 "ABW" 1997 1000 10 500 2 40 20 20 30 "ABW" 1998 1000 10 500 2 40 20 20 30 "ABW" 1999 1000 10 500 2 40 20 20 30 "ABW" 2000 1000 10 500 2 40 20 20 30 "ABW" 2001 1000 10 500 2 40 20 20 30 "ABW" 2002 1000 10 500 2 40 20 20 30 "ABW" 2003 1000 10 500 2 40 20 20 30 "ABW" 2004 1000 10 500 2 40 20 20 30 "ABW" 2005 1000 10 500 2 40 20 20 30 "ABW" 2006 1000 10 500 2 40 20 20 30 "ABW" 2007 1000 10 500 2 40 20 20 30 "ABW" 2008 1000 10 500 2 40 20 20 30 "ABW" 2009 1000 10 500 2 40 20 20 30 "ABW" 2010 1000 10 500 2 40 20 20 30 "ABW" 2011 1000 10 500 2 40 20 20 30 "ABW" 2012 1000 10 500 2 40 20 20 30 "ABW" 2013 1000 10 500 2 40 20 20 30 "ABW" 2014 1000 10 500 2 40 20 20 30 "AFG" 1970 1000 10 500 2 40 20 20 30 "AFG" 1971 1000 10 500 2 40 20 20 30 "AFG" 1972 1000 10 500 2 40 20 20 30 "AFG" 1973 1000 10 500 2 40 20 20 30 "AFG" 1974 1000 10 500 2 40 20 20 30 "AFG" 1975 1000 10 500 2 40 20 20 30 "AFG" 1976 1000 10 500 2 40 20 20 30 "AFG" 1977 1000 10 500 2 40 20 20 30 "AFG" 1978 1000 10 500 2 40 20 20 30 "AFG" 1979 1000 10 500 2 40 20 20 30 "AFG" 1980 1000 10 500 2 40 20 20 30 "AFG" 1981 1000 10 500 2 40 20 20 30 "AFG" 1982 1000 10 500 2 40 20 20 30 "AFG" 1983 1000 10 500 2 40 20 20 30 "AFG" 1984 1000 10 500 2 40 20 20 30 "AFG" 1985 1000 10 500 2 40 20 20 30 "AFG" 1986 1000 10 500 2 40 20 20 30 "AFG" 1987 1000 10 500 2 40 20 20 30 "AFG" 1988 1000 10 500 2 40 20 20 30 "AFG" 1989 1000 10 500 2 40 20 20 30 "AFG" 1990 1000 10 500 2 40 20 20 30 "AFG" 1991 1000 10 500 2 40 20 20 30 "AFG" 1992 1000 10 500 2 40 20 20 30 "AFG" 1993 1000 10 500 2 40 20 20 30 "AFG" 1994 1000 10 500 2 40 20 20 30 "AFG" 1995 1000 10 500 2 40 20 20 30 "AFG" 1996 1000 10 500 2 40 20 20 30 "AFG" 1997 1000 10 500 2 40 20 20 30 "AFG" 1998 1000 10 500 2 40 20 20 30 "AFG" 1999 1000 10 500 2 40 20 20 30 "AFG" 2000 1000 10 500 2 40 20 20 30 "AFG" 2001 1000 10 500 2 40 20 20 30 "AFG" 2002 1000 10 500 2 40 20 20 30 "AFG" 2003 1000 10 500 2 40 20 20 30 "AFG" 2004 1000 10 500 2 40 20 20 30 "AFG" 2005 1000 10 500 2 40 20 20 30 "AFG" 2006 1000 10 500 2 40 20 20 30 "AFG" 2007 1000 10 500 2 40 20 20 30 "AFG" 2008 1000 10 500 2 40 20 20 30 "AFG" 2009 1000 10 500 2 40 20 20 30 "AFG" 2010 1000 10 500 2 40 20 20 30 "AFG" 2011 1000 10 500 2 40 20 20 30 "AFG" 2012 1000 10 500 2 40 20 20 30 "AFG" 2013 1000 10 500 2 40 20 20 30 "AFG" 2014 1000 10 500 2 40 20 20 30 "AGO" 1970 1000 10 500 2 40 20 20 30 "AGO" 1971 1000 10 500 2 40 20 20 30 "AGO" 1972 1000 10 500 2 40 20 20 30 "AGO" 1973 1000 10 500 2 40 20 20 30 "AGO" 1974 1000 10 500 2 40 20 20 30 "AGO" 1975 1000 10 500 2 40 20 20 30 "AGO" 1976 1000 10 500 2 40 20 20 30 "AGO" 1977 1000 10 500 2 40 20 20 30 "AGO" 1978 1000 10 500 2 40 20 20 30 "AGO" 1979 1000 10 500 2 40 20 20 30 end
Best,
Ryan
Comment